chiark / gitweb /
fishdescriptor: bugfixes
[chiark-utils.git] / fishdescriptor / py / fishdescriptor / fish.py
index 95694ff2eaceac3eb59c1b0d672eadf9405c0885..78bb2d86a8725466c47f2a9c2e38d55694c9ca2f 100644 (file)
@@ -6,29 +6,29 @@ import os
 import pwd
 
 def _shuffle_fd3():
-    os.dup(1,3)
-    os.dup(2,1)
+    os.dup2(1,3)
+    os.dup2(2,1)
 
 class Donor():
     def __init__(d, pid):
         d._pid = pid
         d._sp = subprocess.Popen(
-            preexec_fn = _suffle_fd3,
+            preexec_fn = _shuffle_fd3,
             stdin = subprocess.PIPE,
             stdout = subprocess.PIPE,
             close_fds = False,
-            args = ['gdb', '-p', pid, '-batch', '-ex'
+            args = ['gdb', '-p', str(pid), '-batch', '-ex',
                     'python import fishdescriptor.indonor as id;'+
                     ' id.DonorImplementation().eval_loop()'
                 ]
         )            
 
     def _eval_integer(d, expr):
-        l = d._sp.stdin.readline()
-        if l != '!\n': raise RuntimeError("indonor said %s" % repr(l))
-        d._sp.stdout.write(expr + '\n')
-        d._sp.stdout.flush()
-        l = d._sp.stdin.readline().rstrip('\n')
+        l = d._sp.stdout.readline()
+        if l != b'!\n': raise RuntimeError("indonor said %s" % repr(l))
+        d._sp.stdin.write(expr.encode('utf-8') + b'\n')
+        d._sp.stdin.flush()
+        l = d._sp.stdout.readline().rstrip(b'\n')
         return int(l)
 
     def _eval_success(d, expr):
@@ -50,7 +50,7 @@ class Donor():
         ap = subprocess.Popen(
             stdin = subprocess.DEVNULL,
             stdout = subprocess.PIPE,
-            args = ['perl','-we',perl_script] + fds
+            args = ['perl','-we',perl_script] + [str(x) for x in fds]
         )
         (output, dummy) = ap.communicate()
         return output
@@ -76,11 +76,11 @@ class Donor():
     def _sock_dir(d, target_euid):
         run_dir = '/run/user/%d' % target_euid
         if d._exists(run_dir):
-            return run_dir + 'fishdescriptor'
+            return run_dir + '/fishdescriptor'
 
         try:
             pw = pwd.getpwuid(target_euid)
-            return pw.pw_dir + '.fishdescriptor'
+            return pw.pw_dir + '/.fishdescriptor'
         except KeyError:
             pass
 
@@ -98,7 +98,7 @@ class Donor():
 
         sockname = '%s/%s,%d' % (sockdir, os.uname().nodename, d._pid)
 
-        target_root = '/proc/%d/root/' % d._pid
+        target_root = '/proc/%d/root' % d._pid
         if not d._exists(target_root):
             target_root = ''