chiark / gitweb /
Bump version to 7.0.1~iwj0
[chiark-utils.git] / fishdescriptor / py / fishdescriptor / fish.py
index 9d2d3c631fbead808ec46e3c5751819606419458..7588010d6833b976e0f255a1f1aa3f14f25c9d53 100644 (file)
@@ -29,6 +29,7 @@ import struct
 import tempfile
 import shutil
 import sys
+import errno
 
 def _shuffle_fd3():
     os.dup2(1,3)
@@ -111,12 +112,12 @@ class Donor():
             os.stat(path)
             return True
         except OSError as oe:
-            if oe.errno != os.errno.ENOENT: raise oe
+            if oe.errno != errno.ENOENT: raise oe
             return False
 
-    def _sock_dir(d, target_euid):
+    def _sock_dir(d, target_euid, target_root):
         run_dir = '/run/user/%d' % target_euid
-        if d._exists(run_dir):
+        if d._exists(target_root + run_dir):
             return run_dir + '/fishdescriptor'
 
         try:
@@ -133,16 +134,16 @@ class Donor():
     def fish(d, fds):
         # -> list of fds in our process
 
+        target_root = '/proc/%d/root' % d.pid
+        if not d._exists(target_root):
+            target_root = ''
+
         euid = d._geteuid()
-        sockdir = d._sock_dir(euid)
+        sockdir = d._sock_dir(euid, target_root)
         d.mkdir(sockdir)
 
         sockname = '%s/%s,%d' % (sockdir, os.uname().nodename, d.pid)
 
-        target_root = '/proc/%d/root' % d.pid
-        if not d._exists(target_root):
-            target_root = ''
-
         our_sockname = target_root + sockname
 
         s = None