From 791d0447aa2bdd4fe4ae0c76052e09acca4c61f2 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 29 Oct 2026 14:27:42 -0300 Subject: daemon.zig: a forked session takes its stub's death, a SIGKILL too, as the terminal's HUP and detaches PR_SET_PDEATHSIG (FreeBSD: PROC_PDEATHSIG_CTL) in the session child, cleared again at Detach so the stub's own exit then is no hangup; a stub dead before it was set hangs up at once. It is the HUP the signal thread already takes (blocked in every thread, sigwaited), and setsid does not touch it. An --attach stub is no parent of its session: one killed so still leaves the session drawing until the terminal closes or Detach. test/daemon.py kills a session's stub outright under a shell that keeps the terminal (on FreeBSD the session leader's exit revokes it), waits for the session to put the terminal back and detach, and attaches it again; without the death signal it times out. Co-Authored-By: Claude Opus 5.5 --- test/daemon.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/daemon.py b/test/daemon.py index f4f46286..9e9ea600 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -217,15 +217,39 @@ def main(binary, cycles): time.sleep(.3) assert alive(shell_pid), 'a killed session\'s shell is not hung up' assert alive(daemon) + # Started from a shell, which leads the terminal's session and + # outlives the stub, as a terminal's shell does (on FreeBSD the + # leader's exit revokes the terminal for every process). term = Term() - stub = term.spawn([binary, '--tty', '--9p=fresh'], env) - started.append(stub.pid) + stub_pid = root / 'stub.pid' + shell = term.spawn(['sh', '-c', '"$@" & echo $! > "$0"; wait; exec sleep 600', + str(stub_pid), binary, '--tty', '--9p=fresh'], env) + started.append(shell.pid) sock = root / 'pardes-9p-fresh.sock' wait_for('the second session', sock.exists) + stub = int(stub_pid.read_text()) + started.append(stub) client = Client(sock) status = dict(line.split(maxsplit=1) for line in client.read('/status').decode().splitlines()) session = int(status['pid']) started.append(session) + # Its stub killed outright, the terminal left open: the session + # (the stub's child) takes that as the terminal's end and detaches. + wait_for('the second session\'s first frame', lambda: b'\x1b[?1049h' in term.text()) + drawn = len(term.text()) + os.kill(stub, signal.SIGKILL) + wait_for('the stub gone', lambda: not alive(stub)) + wait_for('the session detached from its killed stub', lambda: sized(client)) + assert b'\x1b[?1049l' in term.text()[drawn:], 'the terminal is put back' + assert alive(session) + shell.kill() + shell.wait(timeout=10) + term.close() + term = Term() + stub = term.spawn([binary, '--attach=fresh'], env) + wait_for('the attached terminal\'s first frame', lambda: b'\x1b[?1049h' in term.text()) + wait_for('the session sized to its new terminal', lambda: not sized(client)) + print('daemon: a session whose stub was killed outright detached, and was attached again') before = set(terminals(client)) client.write(f'/pane/{min(before)}/exec', b'Adopt\n') adopted = wait_for('the adopted pane', lambda: set(terminals(client)) - before) -- cgit v1.3