chiark / gitweb /
fishdescriptor: Fix a tuple bug in fd permutation
[chiark-utils.git] / fishdescriptor / fishdescriptor
index 20eddfef05936e38aa17a0bc29bcd8f8ebe2d58c..d583533c210faf64d351f1536af350fceafe887c 100755 (executable)
@@ -1,5 +1,24 @@
 #!/usr/bin/python3
 
+# This file is part of chiark-utils, a collection of useful programs
+# used on chiark.greenend.org.uk.
+#
+# This file is:
+#  Copyright 2018 Citrix Systems Ltd
+#
+# This is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 3, or (at your option) any later version.
+#
+# This is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, consult the Free Software Foundation's
+# website at www.fsf.org, or the GNU Project website at www.gnu.org.
+
 import sys
 import fishdescriptor.fish
 import optparse
@@ -13,7 +32,7 @@ donor = None
 usage = '''fishdescriptor [-p|--pid] <pid> <action>... [-p|--pid <pid> <action>...]
 
 <action>s
-  [<here-0fd>=]<there-fd>
+  [<here-fd>=]<there-fd>
           fish the openfile referenced by descriptor <there-fd> in
           (the most recent) <pid> and keep a descriptor onto it;
           and, optionally, give it the number <here-fd> for exec
@@ -35,12 +54,15 @@ fdmap = { }
 # fdmap[nominal] = (actual, Donor, there)
 
 def implement_pending():
-    actuals = donor.fish([pend[1] for pend in pending])
+    try: actuals = donor.fish([pend[1] for pend in pending])
+    except fishdescriptor.fish.Error as e:
+        print('fishdescriptor error: %s' % e, file=sys.stderr)
+        sys.exit(127)
     assert(len(actuals) == len(pending))
     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)
+        fdmap[nominal] = [actual, donor, there]
 
 def implement_sockinfo(nominal):
     (actual, tdonor, there) = fdmap[nominal]
@@ -104,7 +126,7 @@ def permute_fds_for_exec():
             if inway_intended is not None:
                 inway_moved = os.dup(intended)
                 actual2intended[inway_moved] = inway_intended
-                fdmap[inway_intented][0] = inway_moved
+                fdmap[inway_intended][0] = inway_moved
             os.dup2(actual, intended)
         os.close(actual)