chiark / gitweb /
fishdescriptor: bugfixes
[chiark-utils.git] / fishdescriptor / py / fishdescriptor / indonor.py
index fe0b78d9f5f59013d4cc21f2606a5e0a6594e81c..51b5a3de9940f6ec742813b84450d9efdd31d979 100644 (file)
@@ -37,11 +37,11 @@ def _lit_string_uncasted(s):
 def _lit_array(elemtype, val_lit_strs):
     return (
         '((%s[%d])%s)' %
-        (elem_type, len(val_lit_strs), _lit_aggregate_uncasted(val_lit_strs))
+        (elemtype, len(val_lit_strs), _lit_aggregate_uncasted(val_lit_strs))
     )
 
 def _lit_addressof(v):
-    return '&(%s)' % v
+    return '&(char[])(%s)' % v
 
 def _make_lit(v):
     if isinstance(v, int):
@@ -115,10 +115,10 @@ class DonorImplementation():
     # wrappers for the syscalls that do what we want
 
     def _sendmsg(di, carrier, control_msg):
-        iov_base = _lit_array('int', [str(x) for x in fds])
+        iov_base = _lit_array('char', [1])
         iov = di._make('struct iovec', {
             'iov_base': iov_base,
-            'iov_len' : len(fds),
+            'iov_len' : 1,
         })
 
         msg = di._make('struct msghdr', {
@@ -129,7 +129,7 @@ class DonorImplementation():
         })
 
         di._must_func(
-            'ssize_t (*)(int, const struct msghdr*, int flags)',
+            'ssize_t (*)(int, const struct msghdr*, int)',
             'sendmsg',
             '(%s, %s, 0)' % (carrier, _lit_addressof(msg))
         )
@@ -227,7 +227,9 @@ class DonorImplementation():
         di._result('%d\n' % val)
 
     def _protocol_read(di):
-        input = sys.stdin.readline().rstrip('\n')
+        input = sys.stdin.readline()
+        if input == '': return None
+        input.rstrip('\n')
         sys.stderr.write("#< %s\n" % input)
         return input
 
@@ -235,4 +237,5 @@ class DonorImplementation():
         while True:
             di._result('!\n')
             cmd = di._protocol_read()
+            if cmd is None: break
             eval(cmd)