diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-30 21:35:50 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:17 -0300 |
| commit | 4e5719a133030e8ed29799d4959bb0b917092d7c (patch) | |
| tree | d933325f8bc15e4484385c5b00f64b63794ffa20 /test | |
| parent | 20685b048fcb307840451471679339c9b9704b23 (diff) | |
| download | pardes-4e5719a133030e8ed29799d4959bb0b917092d7c.tar.gz pardes-4e5719a133030e8ed29799d4959bb0b917092d7c.zip | |
An editor killed with SIGTERM or SIGHUP removes its 9P socket, and a start sweeps the pardes-9p-<pid>.sock files whose pid is gone
The runtime directory had gathered a hundred sockets of dead editors:
only a clean exit removed its own, and a signal or a crash left it. The
terminal's kill handler and, where nothing else handles the signals, a
handler of the listener's own now unlink the socket before the signal's
death. At listen, each pardes-9p-<pid>.sock whose pid kill(pid, 0)
answers ESRCH for, that is a socket of this user's and that nothing
answers on, is removed; a live pid's, a named session's and anything
else are never touched.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'test')
| -rw-r--r-- | test/fs.py | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -6,6 +6,7 @@ import os import shutil import select import signal +import socket from pathlib import Path import subprocess import struct @@ -1413,13 +1414,25 @@ def test(binary, quic=False): # Killed with SIGTERM or SIGHUP, a tty editor puts its terminal # back (main screen, cooked mode) before it dies: a nested one # killed in a pane leaves that pane usable. + # ...and its 9P socket goes with it. One a dead editor left behind + # (no process has its pid) is swept at the next start; a live + # pid's, here this test's own, never is. + def unix_socket_file(path): + made = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + made.bind(str(path)) + made.close() for sig in (signal.SIGTERM, signal.SIGHUP): + dead_socket = root / 'pardes-9p-2147483647.sock' + live_socket = root / f'pardes-9p-{os.getpid()}.sock' + for path in (dead_socket, live_socket): + if not path.exists(): + unix_socket_file(path) master, slave = os.openpty() fcntl.ioctl(slave, termios.TIOCSWINSZ, struct.pack('HHHH', 24, 80, 0, 0)) cooked = termios.tcgetattr(slave) env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_')} env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), TERM='xterm-256color', PARDES_NOTIME='1') - killed = subprocess.Popen([binary, '--tty', '--9p=killed', 'x.txt'], cwd=root, env=env, + killed = subprocess.Popen([binary, '--tty', 'x.txt'], cwd=root, env=env, stdin=slave, stdout=slave, stderr=subprocess.DEVNULL, start_new_session=True, preexec_fn=lambda: fcntl.ioctl(0, termios.TIOCSCTTY, 0)) @@ -1431,8 +1444,13 @@ def test(binary, quic=False): if select.select([master], [], [], .1)[0]: seen += os.read(master, 65536) time.sleep(.3) + own_socket = root / f'pardes-9p-{killed.pid}.sock' + assert own_socket.exists() + assert not dead_socket.exists() + assert live_socket.exists() killed.send_signal(sig) assert killed.wait(timeout=5) == -sig + assert not own_socket.exists(), own_socket while select.select([master], [], [], .2)[0]: try: chunk = os.read(master, 65536) |
