uvms-guest: select() to detect dead subprocesses
This commit is contained in:
parent
dd6609ba3f
commit
00ae88e8ad
3 changed files with 127 additions and 70 deletions
|
|
@ -452,18 +452,21 @@ def removing(*paths):
|
|||
os.remove(p)
|
||||
|
||||
|
||||
@contextmanager
|
||||
def connect_ch_vsock(
|
||||
vsock_sock_path,
|
||||
port: int,
|
||||
type=socket.SOCK_STREAM,
|
||||
blocking=True,
|
||||
) -> socket.socket:
|
||||
os.makedirs(os.path.dirname(vsock_sock_path), exist_ok=True)
|
||||
s = socket.socket(socket.AF_UNIX, type, 0)
|
||||
s.setblocking(blocking)
|
||||
s.connect(vsock_sock_path)
|
||||
|
||||
s.send(b"CONNECT %d\n" % port)
|
||||
return s
|
||||
with removing(vsock_sock_path):
|
||||
s.send(b"CONNECT %d\n" % port)
|
||||
yield s
|
||||
|
||||
|
||||
@contextmanager
|
||||
|
|
@ -473,15 +476,14 @@ def listen_ch_vsock(
|
|||
type=socket.SOCK_STREAM,
|
||||
blocking=True,
|
||||
) -> socket.socket:
|
||||
os.makedirs(os.path.dirname(vsock_sock_path), exist_ok=True)
|
||||
listen_path = vsock_sock_path + "_%d" % port
|
||||
s = socket.socket(socket.AF_UNIX, type, 0)
|
||||
s.setblocking(blocking)
|
||||
s.bind(listen_path)
|
||||
s.listen()
|
||||
try:
|
||||
with removing(listen_path):
|
||||
yield s
|
||||
finally:
|
||||
os.remove(listen_path)
|
||||
|
||||
|
||||
def main(args, args_next, cleanup, ps):
|
||||
|
|
@ -589,7 +591,7 @@ def main(args, args_next, cleanup, ps):
|
|||
ps.exec(*ch_remote, "info")
|
||||
|
||||
with ready_sock:
|
||||
ready_sock.settimeout(16.0)
|
||||
ready_sock.settimeout(20.0)
|
||||
try:
|
||||
con, _ = ready_sock.accept()
|
||||
except: # noqa: E722
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue