diff options
Diffstat (limited to 'src/9p_io.zig')
| -rw-r--r-- | src/9p_io.zig | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/9p_io.zig b/src/9p_io.zig index a089a7cf..2a0061fd 100644 --- a/src/9p_io.zig +++ b/src/9p_io.zig @@ -975,13 +975,14 @@ pub fn unlinkOwnSocket() void { _ = libc.unlink(own_socket[0..n :0]); } -/// SIGTERM and SIGHUP with no handler of their own (a GUI's): the socket -/// goes, then the signal's own death. A host that handles them itself (the -/// terminal's Killed, the detached server's quit) removes it its own way. +/// SIGTERM, SIGHUP and SIGINT with no handler of their own (a GUI's, a +/// detached session's): the socket goes, then the signal's own death. A +/// host that handles them itself (the terminal's Killed, SDL's quit) +/// removes it its own way. fn armSocketCleanup() void { const sig = std.posix.SIG; const on: std.posix.Sigaction = .{ .handler = .{ .handler = onFatalSignal }, .mask = std.posix.sigemptyset(), .flags = std.posix.SA.RESETHAND }; - for ([_]std.posix.SIG{ sig.TERM, sig.HUP }) |s| { + for ([_]std.posix.SIG{ sig.TERM, sig.HUP, sig.INT }) |s| { var was: std.posix.Sigaction = undefined; std.posix.sigaction(s, null, &was); if (was.handler.handler == sig.DFL) std.posix.sigaction(s, &on, null); @@ -995,6 +996,8 @@ pub var fatal_cleanup: ?*const fn () void = null; fn onFatalSignal(s: std.posix.SIG) callconv(.c) void { unlinkOwnSocket(); if (fatal_cleanup) |cleanup| cleanup(); + // Its shells go with it, the daemon's dups let go. + @import("daemon.zig").hangUp(); // SA_RESETHAND put the default back: the same signal, now fatal. _ = std.c.raise(s); } @@ -1204,6 +1207,17 @@ pub fn listen(io: std.Io, gpa: std.mem.Allocator, core: *pardes.Pardes, named: [ const alive = transport.isListening; +/// Whether a live session listens under `name` already: a second +/// `--detach=<name>` is refused before anything is made. +pub fn taken(name: []const u8) bool { + if (comptime !supported) return false; + var dir_buf: [sun_path_len:0]u8 = undefined; + const dir = socketDir(&dir_buf) orelse return false; + var buf: [sun_path_len]u8 = undefined; + const p = socketPath(&buf, dir, name) orelse return false; + return statNoFollow(p) != null and alive(p); +} + /// What is at a socket path, in cloud9's three answers (`post.Probe`). /// Asked here with libc rather than through `cloud9.post.probe`, whose /// raw Linux syscalls darwin cannot compile, but the classification is |
