summaryrefslogtreecommitdiff
path: root/src/daemon.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 23:12:51 -0300
committerGabriel Schneider <[email protected]>2026-11-05 09:54:56 -0300
commitba3f55e71325f31399fbd2134868d6ba7f774451 (patch)
treede694d2ef5847f4886d438c53297d7265aa889a4 /src/daemon.zig
parentf0eba0a5f07b88546cefe530f915302b203d0e6c (diff)
downloadpardes-ba3f55e71325f31399fbd2134868d6ba7f774451.tar.gz
pardes-ba3f55e71325f31399fbd2134868d6ba7f774451.zip
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 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/daemon.zig')
-rw-r--r--src/daemon.zig30
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);
}