X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-utils.git;a=blobdiff_plain;f=fishdescriptor%2Ffishdescriptor;fp=fishdescriptor%2Ffishdescriptor;h=b8c732a67270a5785b42e47bcf8d0915c6d696d0;hp=7150df2b31fc587f711b3826a7a90a296558e0de;hb=54e807bb078502c144f02399fccf3c2056ac3723;hpb=6f3a1bd6659dd7e724db2e2f18f62bf331e63421 diff --git a/fishdescriptor/fishdescriptor b/fishdescriptor/fishdescriptor index 7150df2..b8c732a 100755 --- a/fishdescriptor/fishdescriptor +++ b/fishdescriptor/fishdescriptor @@ -2,6 +2,66 @@ import sys import fishdescriptor.fish +import re + +donor = None + +usage = +''' +fishdescriptor ... [-p|--pid ...] + +s + [=] + fish the openfile referenced by descriptor in + (the most recent) and keep a descriptor onto it; + and, optionally, give it the number for exec + exec [...] + execute a process with each specified numeric + as an actual fd + sockinfo + calls getsockname/getpeername on the most recent + + + -p|-pid + now attach to , detaching from previous pid +''' + +def set_donor(pid_arg): + pid = int(pid_arg) + if donor is not None: donor.detach() + donor = fishdescriptor.fish.Donor(pid) + +def process_args(): + def arg_matches(regexp): + nonlocal m + m = re.search(regexp, arg) + return m + + arg_ix = 0 + def next_arg(): + sys.argv[arg_ix] = + + while arg_ix < len(sys.argv): + arg = next_arg() + if arg_matches(r'^-p(\d+)') or + arg_matches(r'^--pid=(\d+)$') + set_donor(m.groups(1)[0]) + + pid = +(?:-p|^--pid(?:=|$))(\d*)$'): + + pid = int(m.groups(1)[0]) + elif arg_matches(r'^(?:-p|^--pid=)(\d+)$'): + + if expecting_pid: + set_donor(arg) + el + elif arg_matches(r'\d+ + + parser = OptionParser(usage=usage, ) + + parser.add_option("-p", "--pid", type='int', callback=set_donor) + parser.add_option( pid = int(sys.argv[1]) fds = [int(x) for x in sys.argv[2:]]