summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-08 20:50:30 -0300
committerGabriel Schneider <[email protected]>2026-11-08 21:48:19 -0300
commite9e074c1e70f7a6c941deca31116882c434fd3b7 (patch)
treecb299c28e89e255e8a2c448c18ed092c59ce71d4 /src
parentd31cc9eb97da97e3cb5268565ced3bf8c25f8540 (diff)
downloadpardes-e9e074c1e70f7a6c941deca31116882c434fd3b7.tar.gz
pardes-e9e074c1e70f7a6c941deca31116882c434fd3b7.zip
fix: a window handover under a runtime directory too long for a window's 9P socket made the window and waited 15 s on a registry entry that could never answer (past ~490 bytes its path was empty): it says so first, no new window: XDG_RUNTIME_DIR is N bytes, too long for its 9P socket; daemon.find's reason for a name past its room is cut, never empty (Zig 0.17's bufPrint writes what fits), and a test pins that
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src')
-rw-r--r--src/Handover.zig47
-rw-r--r--src/daemon.zig10
2 files changed, 55 insertions, 2 deletions
diff --git a/src/Handover.zig b/src/Handover.zig
index 0abcf859..1b4fed7d 100644
--- a/src/Handover.zig
+++ b/src/Handover.zig
@@ -402,12 +402,17 @@ fn carry(io: std.Io, job: *Job) void {
name, if (err == error.Remote) ninep_io.Client.lastSaid() else @errorName(err),
}) catch "the window would not take it");
}
+ // A runtime directory a window's socket cannot be made in (9p_io's
+ // `<dir>/pardes-9p-<pid>.sock.<pid>`, a pid at most 7 digits) is said
+ // before a window is made that could never answer.
+ const run = std.mem.span(libc.getenv("XDG_RUNTIME_DIR") orelse "");
+ if (run.len + "/pardes-9p-.sock.".len + 2 * "4194304".len + 1 > ninep_io.sun_path_len)
+ return job.post(job.post_ctx, job.seq, false, std.fmt.bufPrint(&words, "no new window: XDG_RUNTIME_DIR is {d} bytes, too long for its 9P socket", .{run.len}) catch unreachable); // a number fits 256
const pid = spawnWindow(job) catch |err| return job.post(job.post_ctx, job.seq, false, std.fmt.bufPrint(&words, "no new window: {s}", .{@errorName(err)}) catch "no new window");
// Up when its registry entry answers: it read the dump before it
// listened (gui.localSession), so the file is no longer needed.
var entry_buf: [512]u8 = undefined;
- const run = libc.getenv("XDG_RUNTIME_DIR") orelse "";
- const entry = std.fmt.bufPrint(&entry_buf, "{s}/9p/pardes/{d}", .{ std.mem.span(run), pid }) catch "";
+ const entry = std.fmt.bufPrint(&entry_buf, "{s}/9p/pardes/{d}", .{ run, pid }) catch unreachable; // under sun_path, checked above
var waited: u32 = 0;
while (waited < 15_000) : (waited += 50) {
if (libc.kill(pid, @enumFromInt(0)) != 0)
@@ -652,3 +657,41 @@ test "a column let go over another window goes beside the column the pointer is
from.update(.{ .handed = .{ .seq = from.handover.seq, .to = "pardes/2" } });
try std.testing.expect(from.view().ncol == 1 or from.view().cols[c].n == 0 or layout.findPane(from, 0) == null);
}
+
+extern "c" fn setenv(name: [*:0]const u8, value: [*:0]const u8, overwrite: c_int) c_int;
+
+test "a handover under a runtime directory too long for a window's socket is refused in words, no window made" {
+ if (comptime builtin.os.tag != .linux) return error.SkipZigTest;
+ const gpa = std.testing.allocator;
+ const Said = struct {
+ var ok: ?bool = null;
+ var buf: [256]u8 = undefined;
+ var len: usize = 0;
+ fn post(_: ?*anyopaque, _: u32, ok_: bool, words: []const u8) void {
+ ok = ok_;
+ len = @min(words.len, buf.len);
+ @memcpy(buf[0..len], words[0..len]);
+ }
+ };
+ const old = if (libc.getenv("XDG_RUNTIME_DIR")) |v| try gpa.dupeSentinel(u8, std.mem.span(v), 0) else null;
+ defer if (old) |v| {
+ _ = setenv("XDG_RUNTIME_DIR", v, 1);
+ gpa.free(v);
+ } else {
+ _ = @import("host_io.zig").testUnsetenv("XDG_RUNTIME_DIR");
+ };
+ // The ledger's case, past 490 bytes, and one past sun_path alone.
+ for ([_]usize{ 600, 100 }) |n| {
+ var dir_buf: [601:0]u8 = undefined;
+ @memset(dir_buf[0..n], 'r');
+ dir_buf[0] = '/';
+ dir_buf[n] = 0;
+ try std.testing.expectEqual(@as(c_int, 0), setenv("XDG_RUNTIME_DIR", dir_buf[0..n :0], 1));
+ const job = try gpa.create(Job);
+ job.* = .{ .gpa = gpa, .seq = 1, .path = try gpa.dupeSentinel(u8, "/nonexistent/pardes-handover.xitdb", 0), .post = Said.post, .post_ctx = null };
+ Said.ok = null;
+ carry(std.testing.io, job);
+ try std.testing.expectEqual(@as(?bool, false), Said.ok);
+ try std.testing.expect(std.mem.indexOf(u8, Said.buf[0..Said.len], "XDG_RUNTIME_DIR is") != null);
+ }
+}
diff --git a/src/daemon.zig b/src/daemon.zig
index f02c339e..84c77f90 100644
--- a/src/daemon.zig
+++ b/src/daemon.zig
@@ -1232,3 +1232,13 @@ test "a message carries its words and its fds, and the peer's end is null" {
_ = libc.close(pair[1]);
try std.testing.expect(recv(pair[0], &buf) == null);
}
+
+test "an attach by a name longer than any session's is refused in words, never an empty reason" {
+ var d: Daemon = .{};
+ var why: [512]u8 = undefined;
+ const long: []const u8 = &@as([600]u8, @splat('n'));
+ try std.testing.expect(d.find(.tty, long, &why) == null);
+ const said = std.mem.sliceTo(&why, 0);
+ try std.testing.expect(std.mem.startsWith(u8, said, "no "));
+ try std.testing.expect(said.len > "no ".len);
+}