import fishdescriptor.fish
import optparse
import re
+import subprocess
+import socket
+import os
donor = None
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 implmement_sockinfo(nominal):
+def implement_sockinfo(nominal):
(actual, tdonor, there) = fdmap[nominal]
# socket.fromfd requires the AF. But of course we don't know the AF.
# There isn't a sane way to get it in Python:
(output, dummy) = famp.communicate()
family = int(output)
- sock = socket.fromfd(fd, family, 0)
+ sock = socket.fromfd(actual, family, 0)
print("[%s] %d sockinfo" % (tdonor.pid, there), end='')
for f in (lambda: socket.AddressFamily(family).name,
sock.close()
def permute_fds_for_exec():
- actual2intended = { info[0]: nominal for nominal, info in fdmap.items }
+ actual2intended = { info[0]: nominal for nominal, info in fdmap.items() }
# invariant at the start of each loop iteration:
# for each intended (aka `nominal') we have processed:
# relevant open-file is only held in fd intended
def implement_exec(argl):
if donor is not None: donor.detach()
sys.stdout.flush()
- permut_fds_for_exec()
+ permute_fds_for_exec()
os.execvp(argl[0], argl)
def set_donor(pid):
callback=ocb_set_donor)
args = sys.argv[1:]
- last_nominal = None
+ last_nominal = None # None or (nominal,) ie None or (None,) or (int,)
while True:
(ov, args) = op.parse_args(args=args, values=ov)
if not len(args): break
arg = args.pop(0)
+ print("ARG %s" % arg, file=sys.stderr)
- if donor is not None:
+ if donor is None:
+ print("SET_DONOR", file=sys.stderr)
set_donor(int(arg))
elif arg_matches(r'^(?:(\d+)=)?(\d+)?$'):
(nominal, there) = m.groups()
nominal = None if nominal is None else int(nominal)
there = int(there)
pending.append((nominal,there))
- last_nominal = nominal
+ last_nominal = (nominal,)
elif arg == 'exec':
if not len(args):
op.error("exec needs command to run")
if last_nominal is None:
op.error('sockinfo needs a prior fd spec')
implement_pending()
- implement_sockinfo(last_nominal)
+ implement_sockinfo(last_nominal[0])
else:
op.error("unknown argument/option `%s'" % arg)