Exemplo n.º 1
0
 def execv(filename, args):
     #  Create an O_TEMPORARY file and pass its name to the slave process.
     #  When this master process dies, the file will be deleted and the
     #  slave process will know to terminate.
     try:
         tdir = environ["TEMP"]
     except:
         tdir = None
     if tdir:
         try:
             nt.mkdir(pathjoin(tdir, "esky-slave-procs"), 0600)
         except EnvironmentError:
             pass
         if exists(pathjoin(tdir, "esky-slave-procs")):
             flags = nt.O_CREAT | nt.O_EXCL | nt.O_TEMPORARY | nt.O_NOINHERIT
             for i in xrange(10):
                 tfilenm = "slave-%d.%d.txt" % (nt.getpid(), i)
                 tfilenm = pathjoin(tdir, "esky-slave-procs", tfilenm)
                 try:
                     os_open(tfilenm, flags, 0600)
                     args.insert(1, tfilenm)
                     args.insert(1, "--esky-slave-proc")
                     break
                 except EnvironmentError:
                     pass
     # Ensure all arguments are quoted (to allow spaces in paths)
     for i, arg in enumerate(args):
         if arg[0] != '"' and args[-1] != '"':
             args[i] = '"{}"'.format(arg)
     res = spawnv(P_WAIT, filename, args)
     _exit_code[0] = res
     raise SystemExit(res)
Exemplo n.º 2
0
def lock_version_dir(vdir):
    """Lock the given version dir so it cannot be uninstalled."""
    if sys.platform == "win32":
        #  On win32, we just hold bootstrap file open for reading.
        #  This will prevent it from being renamed during uninstall.
        lockfile = pathjoin(vdir, ESKY_CONTROL_DIR, "bootstrap-manifest.txt")
        _locked_version_dirs.setdefault(vdir, []).append(os_open(lockfile, 0, 0))
    else:
        #  On posix platforms we take a shared flock on esky-files/lockfile.txt.
        #  While fcntl.fcntl locks are apparently the new hotness, they have
        #  unfortunate semantics that we don't want for this application:
        #      * not inherited across fork()
        #      * released when closing *any* fd associated with that file
        #  fcntl.flock doesn't have these problems, but may fail on NFS.
        #  To complicate matters, python sometimes emulates flock with fcntl!
        #  We therefore use a separate lock file to avoid unpleasantness.
        lockfile = pathjoin(vdir, ESKY_CONTROL_DIR, "lockfile.txt")
        f = os_open(lockfile, 0, 0)
        _locked_version_dirs.setdefault(vdir, []).append(f)
        fcntl.flock(f, fcntl.LOCK_SH)
Exemplo n.º 3
0
def lock_version_dir(vdir):
    """Lock the given version dir so it cannot be uninstalled."""
    if sys.platform == "win32":
        #  On win32, we just hold bootstrap file open for reading.
        #  This will prevent it from being renamed during uninstall.
        lockfile = pathjoin(vdir,ESKY_CONTROL_DIR,"bootstrap-manifest.txt")
        _locked_version_dirs.setdefault(vdir,[]).append(os_open(lockfile,0,0))
    else:
        #  On posix platforms we take a shared flock on esky-files/lockfile.txt.
        #  While fcntl.fcntl locks are apparently the new hotness, they have
        #  unfortunate semantics that we don't want for this application:
        #      * not inherited across fork()
        #      * released when closing *any* fd associated with that file
        #  fcntl.flock doesn't have these problems, but may fail on NFS.
        #  To complicate matters, python sometimes emulates flock with fcntl!
        #  We therefore use a separate lock file to avoid unpleasantness.
        lockfile = pathjoin(vdir,ESKY_CONTROL_DIR,"lockfile.txt")
        f = os_open(lockfile,0,0)
        _locked_version_dirs.setdefault(vdir,[]).append(f)
        fcntl.flock(f,fcntl.LOCK_SH)