diff options
Diffstat (limited to 'src/daemon.zig')
| -rw-r--r-- | src/daemon.zig | 30 |
1 files changed, 8 insertions, 22 deletions
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<name>` detached (one of a session's +/// several terminals, views.zig), `x<code>` exited, `r<why>` 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); } |
