Emulates the most basic behavior of Linux's flock(1).
(self, lockfile, *cmd_list)
| 34 | return name_string.title().replace("-", "") |
| 35 | |
| 36 | def ExecFlock(self, lockfile, *cmd_list): |
| 37 | """Emulates the most basic behavior of Linux's flock(1).""" |
| 38 | # Rely on exception handling to report errors. |
| 39 | # Note that the stock python on SunOS has a bug |
| 40 | # where fcntl.flock(fd, LOCK_EX) always fails |
| 41 | # with EBADF, that's why we use this F_SETLK |
| 42 | # hack instead. |
| 43 | fd = os.open(lockfile, os.O_WRONLY | os.O_NOCTTY | os.O_CREAT, 0o666) |
| 44 | if sys.platform.startswith("aix") or sys.platform == "os400": |
| 45 | # Python on AIX is compiled with LARGEFILE support, which changes the |
| 46 | # struct size. |
| 47 | op = struct.pack("hhIllqq", fcntl.F_WRLCK, 0, 0, 0, 0, 0, 0) |
| 48 | else: |
| 49 | op = struct.pack("hhllhhl", fcntl.F_WRLCK, 0, 0, 0, 0, 0, 0) |
| 50 | fcntl.fcntl(fd, fcntl.F_SETLK, op) |
| 51 | return subprocess.call(cmd_list) |
| 52 | |
| 53 | |
| 54 | if __name__ == "__main__": |