diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-28 16:04:34 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:15 -0300 |
| commit | ffef5a511a14071bd9be9887439a6cb40af3fb92 (patch) | |
| tree | f0e41e84a1f84e04c13ad931444aa8d96c59cc70 /src/detached/server.zig | |
| parent | 4b7ab8a91defb73006d58abd9f6e7cb3d690d669 (diff) | |
| download | pardes-ffef5a511a14071bd9be9887439a6cb40af3fb92.tar.gz pardes-ffef5a511a14071bd9be9887439a6cb40af3fb92.zip | |
A detached session stopped by SIGTERM, SIGINT or SIGHUP unlinks its sockets
The signals' default action ended the process where it stood, leaving
pardes-9p-*.sock and pardes-detached-*.sock for the next session to trip on.
The detached session now takes them to mean quit: the handler sets a flag and
wakes the loop, which leaves as Exit does, through the teardown that unlinks
both. fs.py sends each of the three and checks the sockets are gone.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/detached/server.zig')
| -rw-r--r-- | src/detached/server.zig | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/detached/server.zig b/src/detached/server.zig index 5bf2384b..b47bda1b 100644 --- a/src/detached/server.zig +++ b/src/detached/server.zig @@ -1181,6 +1181,17 @@ pub const Session = struct { } }; +/// SIGTERM, SIGINT or SIGHUP: quit as Exit does, through the loop, so its +/// sockets are unlinked on the way out rather than left for the next +/// session to trip on. The handler only sets the flag and wakes the loop. +var quit_signalled = std.atomic.Value(bool).init(false); +var quit_wake: c_int = -1; + +fn onQuitSignal(_: std.posix.SIG) callconv(.c) void { + quit_signalled.store(true, .release); + if (quit_wake >= 0) _ = libc.send(quit_wake, "q", 1, nosignal); +} + pub fn run(init: std.process.Init, opts: pardes.Options, name: []const u8) !void { const gpa = init.gpa; const allocs = pardes.memory.init(gpa); @@ -1231,7 +1242,11 @@ pub fn run(init: std.process.Init, opts: pardes.Options, name: []const u8) !void core.host = h; while (core.nextEffect()) |effect| core.perform(effect); session.in_loop = true; - while (!session.core.quit) { + quit_wake = session.mailbox.wake[1]; + const on_quit: std.posix.Sigaction = .{ .handler = .{ .handler = onQuitSignal }, .mask = std.posix.sigemptyset(), .flags = 0 }; + for ([_]std.posix.SIG{ .HUP, .INT, .TERM }) |sig| std.posix.sigaction(sig, &on_quit, null); + defer quit_wake = -1; + while (!session.core.quit and !quit_signalled.load(.acquire)) { pardes.turn.restoreSettled(); try session.core.pump(h); if (session.core.quit) break; |
