chiark / gitweb /
fishdescriptor: wip utility, bugfixes
[chiark-utils.git] / fishdescriptor / fishdescriptor
index 863cf83660de3e63525c21ce833ad0b69420830c..8bcb46707c210c8b0436aead2b72aa1b0fb7f5f9 100755 (executable)
@@ -31,16 +31,13 @@ pending = []
 fdmap = { }
 # fdmap[nominal] = (actual, Donor, there)
 
-last_nominal = None
-
 def implement_pending():
     actuals = donor.fish([pend[1] for pend in pending])
     assert(len(actuals) == len(pending))
-    for (nominal, there), actual in zip(pending, actuals)
+    for (nominal, there), actual in zip(pending, actuals):
         overwriting_info = fdmap.get(nominal)
         if overwriting_info is not None: os.close(overwriting_info[0])
         fdmap[nominal] = (actual, Donor, there)
-        last_nominal = nominal
 
 def implmement_sockinfo(nominal):
     (actual, tdonor, there) = fdmap[nominal]
@@ -125,6 +122,10 @@ def ocb_set_donor(option, opt, value, parser):
 ov = optparse.Values()
 
 def process_args():
+    global ov
+
+    m = None
+    
     def arg_matches(regexp):
         nonlocal m
         m = re.search(regexp, arg)
@@ -134,9 +135,10 @@ def process_args():
 
     op.disable_interspersed_args()
     op.add_option('-p','--pid', type='int', action='callback',
-                  callback='ocb_set_donor')
+                  callback=ocb_set_donor)
 
-    args = sys.argv
+    args = sys.argv[1:]
+    last_nominal = None
 
     while True:
         (ov, args) = op.parse_args(args=args, values=ov)
@@ -150,13 +152,14 @@ def process_args():
             (nominal, there) = m.groups()
             nominal = None if nominal is None else int(nominal)
             there = int(there)
-            pending.append = (nominal,there)
-        elif arg = 'exec':
+            pending.append((nominal,there))
+            last_nominal = nominal
+        elif arg == 'exec':
             if not len(args):
                 op.error("exec needs command to run")
             implement_pending()
             implement_exec(args)
-        elif arg = 'sockinfo':
+        elif arg == 'sockinfo':
             if last_nominal is None:
                 op.error('sockinfo needs a prior fd spec')
             implement_pending()
@@ -164,18 +167,4 @@ def process_args():
         else:
             op.error("unknown argument/option `%s'" % arg)
 
-    implement_pending()
-    
-
-            there = int(m.group[1])
-            nominal = None if m.group
-
-            ,nominal) = map(int, m.groups())
-            
-
-pid = int(sys.argv[1])
-fds = [int(x) for x in sys.argv[2:]]
-
-d = fishdescriptor.fish.Donor(pid)
-r = d.fish(fds)
-print(repr(r))
+process_args()