chiark / gitweb /
fishdescriptor: Provide copyright notices and licence statements
[chiark-utils.git] / fishdescriptor / fishdescriptor
index dc1776207d55e62b99acf91f652bc0d46e452d4a..8abdfffc1f39f5a02823bd9284627d8fad5d6f06 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,7 +54,10 @@ 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)
@@ -117,7 +139,7 @@ def implement_exec(argl):
 def set_donor(pid):
     global donor
     if donor is not None: donor.detach()
-    donor = fishdescriptor.fish.Donor(pid)
+    donor = fishdescriptor.fish.Donor(pid, debug=ov.debug)
 
 def ocb_set_donor(option, opt, value, parser):
     set_donor(value)
@@ -139,6 +161,9 @@ def process_args():
     op.disable_interspersed_args()
     op.add_option('-p','--pid', type='int', action='callback',
                   callback=ocb_set_donor)
+    op.add_option('-D','--debug', action='store_const',
+                  dest='debug', const=sys.stderr)
+    ov.debug = None
 
     args = sys.argv[1:]
     last_nominal = None # None or (nominal,) ie None or (None,) or (int,)
@@ -148,10 +173,8 @@ def process_args():
         if not len(args): break
 
         arg = args.pop(0)
-        print("ARG %s" % arg, file=sys.stderr)
 
         if donor is None:
-            print("SET_DONOR", file=sys.stderr)
             set_donor(int(arg))
         elif arg_matches(r'^(?:(\d+)=)?(\d+)?$'):
             (nominal, there) = m.groups()