From ba3f55e71325f31399fbd2134868d6ba7f774451 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 23:12:51 -0300 Subject: daemon: what a stub is told (detached, exited, refused) is one daemon.tellStub(fd, fmt, args), where tellDetached, tellExit and refuseStub each formatted a word into a buffer, wrote it and closed the pipe Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/daemon.zig | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'src/daemon.zig') diff --git a/src/daemon.zig b/src/daemon.zig index eb2b7eed..fff7bbe5 100644 --- a/src/daemon.zig +++ b/src/daemon.zig @@ -608,38 +608,24 @@ pub fn hupOnStubDeath(on: bool) void { pub fn tellStubDetached() void { if (stub < 0) return; hupOnStubDeath(false); - tellDetached(stub); + tellStub(stub, "d{s}", .{name()}); stub = -1; } -/// The stub on `fd` told its terminal is detached (one of a session's -/// several, views.zig), and the pipe let go. -pub fn tellDetached(fd: c_int) void { - if (fd < 0) return; - var buf: [160]u8 = undefined; - const said = std.fmt.bufPrint(&buf, "d{s}", .{name()}) catch "d"; - _ = libc.write(fd, said.ptr, said.len); - _ = libc.close(fd); -} - /// The session's end, `code` its exit status: the stub is told (and goes). pub fn tellStubExit(code: u8) void { - tellExit(stub, code); + tellStub(stub, "x{d}", .{code}); stub = -1; } -pub fn tellExit(fd: c_int, code: u8) void { +/// The stub on `fd` told how its terminal's session went, what stubWait +/// reads, and its pipe let go: `d` detached (one of a session's +/// several terminals, views.zig), `x` exited, `r` refused (an +/// attach that came too late). +pub fn tellStub(fd: c_int, comptime fmt: []const u8, args: anytype) void { if (fd < 0) return; - var buf: [8]u8 = undefined; - const said = std.fmt.bufPrint(&buf, "x{d}", .{code}) catch "x1"; - _ = libc.write(fd, said.ptr, said.len); - _ = libc.close(fd); -} - -/// A terminal refused (an attach that came too late): its stub is told why. -pub fn refuseStub(fd: c_int, why: []const u8) void { var buf: [256]u8 = undefined; - const said = std.fmt.bufPrint(&buf, "r{s}", .{why}) catch "r"; + const said = std.fmt.bufPrint(&buf, fmt, args) catch fmt[0..1]; _ = libc.write(fd, said.ptr, said.len); _ = libc.close(fd); } -- cgit v1.3