Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
gyp: work around sunos python flock() bug
Browse files Browse the repository at this point in the history
flock(LOCK_EX) always fails with EBADF, use fcntl(F_SETLK) instead.
  • Loading branch information
bnoordhuis committed Oct 10, 2011
1 parent e6092f3 commit 6b9f559
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions tools/gyp/pylib/gyp/sun_tool.py
Expand Up @@ -5,11 +5,9 @@

"""These functions are executed via gyp-sun-tool when using the Makefile generator."""

import os
import fcntl
import plistlib
import shutil
import string
import os
import struct
import subprocess
import sys

Expand All @@ -36,6 +34,14 @@ def _CommandifyName(self, name_string):
def ExecFlock(self, lockfile, *cmd_list):
"""Emulates the most basic behavior of Linux's flock(1)."""
# Rely on exception handling to report errors.
fd = os.open(lockfile, os.O_RDONLY|os.O_NOCTTY|os.O_CREAT, 0o666)
fcntl.flock(fd, fcntl.LOCK_EX)
# Note that the stock python on SunOS has a bug
# where fcntl.flock(fd, LOCK_EX) always fails
# with EBADF, that's why we use this F_SETLK
# hack instead.
fd = os.open(lockfile, os.O_WRONLY|os.O_NOCTTY|os.O_CREAT, 0o666)
op = struct.pack('hhllhhl', fcntl.F_WRLCK, 0, 0, 0, 0, 0, 0)
fcntl.fcntl(fd, fcntl.F_SETLK, op)
return subprocess.call(cmd_list)

if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))

0 comments on commit 6b9f559

Please sign in to comment.