chiark
/
gitweb
/
~ian
/
chiark-utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fishdescriptor: Make Donor.pid a public member
[chiark-utils.git]
/
fishdescriptor
/
py
/
fishdescriptor
/
fish.py
diff --git
a/fishdescriptor/py/fishdescriptor/fish.py
b/fishdescriptor/py/fishdescriptor/fish.py
index 78bb2d86a8725466c47f2a9c2e38d55694c9ca2f..15ad7660faa3e19861a8d08cb2dde2106348cdf2 100644
(file)
--- a/
fishdescriptor/py/fishdescriptor/fish.py
+++ b/
fishdescriptor/py/fishdescriptor/fish.py
@@
-4,6
+4,7
@@
import socket
import subprocess
import os
import pwd
import subprocess
import os
import pwd
+import struct
def _shuffle_fd3():
os.dup2(1,3)
def _shuffle_fd3():
os.dup2(1,3)
@@
-11,7
+12,7
@@
def _shuffle_fd3():
class Donor():
def __init__(d, pid):
class Donor():
def __init__(d, pid):
- d.
_
pid = pid
+ d.pid = pid
d._sp = subprocess.Popen(
preexec_fn = _shuffle_fd3,
stdin = subprocess.PIPE,
d._sp = subprocess.Popen(
preexec_fn = _shuffle_fd3,
stdin = subprocess.PIPE,
@@
-53,11
+54,11
@@
class Donor():
args = ['perl','-we',perl_script] + [str(x) for x in fds]
)
(output, dummy) = ap.communicate()
args = ['perl','-we',perl_script] + [str(x) for x in fds]
)
(output, dummy) = ap.communicate()
- return output
+ return output
.decode('utf-8')
def donate(d, path, fds):
ancil = d._ancilmsg(fds)
def donate(d, path, fds):
ancil = d._ancilmsg(fds)
- d._eval_success('di.donate(%s,
%s
)'
+ d._eval_success('di.donate(%s,
[ %s ]
)'
% (repr(path), ancil))
return len(ancil.split(','))
% (repr(path), ancil))
return len(ancil.split(','))
@@
-96,9
+97,9
@@
class Donor():
sockdir = d._sock_dir(euid)
d.mkdir(sockdir)
sockdir = d._sock_dir(euid)
d.mkdir(sockdir)
- sockname = '%s/%s,%d' % (sockdir, os.uname().nodename, d.
_
pid)
+ sockname = '%s/%s,%d' % (sockdir, os.uname().nodename, d.pid)
- target_root = '/proc/%d/root' % d.
_
pid
+ target_root = '/proc/%d/root' % d.pid
if not d._exists(target_root):
target_root = ''
if not d._exists(target_root):
target_root = ''
@@
-116,14
+117,16
@@
class Donor():
s.listen(1)
ancil_len = d.donate(our_sockname, fds)
s.listen(1)
ancil_len = d.donate(our_sockname, fds)
-
s2
= s.accept()
+
(s2, dummy)
= s.accept()
(msg, ancil, flags, sender) = s2.recvmsg(1, ancil_len)
(msg, ancil, flags, sender) = s2.recvmsg(1, ancil_len)
- got_fds = [ ]
+ got_fds = None
+ unpack_fmt = '%di' % len(fds)
for clvl, ctype, cdata in ancil:
if clvl == socket.SOL_SOCKET and ctype == socket.SCM_RIGHTS:
for clvl, ctype, cdata in ancil:
if clvl == socket.SOL_SOCKET and ctype == socket.SCM_RIGHTS:
- got_fds += cdata # need to trim any surplus, and unpack
+ assert(got_fds is None)
+ got_fds = struct.unpack_from(unpack_fmt, cdata)
finally:
if s is not None: s.close()
finally:
if s is not None: s.close()
@@
-131,3
+134,8
@@
class Donor():
try: os.remove(our_sockname)
except FileNotFoundError: pass
try: os.remove(our_sockname)
except FileNotFoundError: pass
+
+ return list(got_fds)
+
+ def detach(d):
+ d._sp.stdin.close()