From 79311cd89746738a20be359c054dc2a7c84577db Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 5 Nov 2026 00:19:33 -0300 Subject: 9p_io: exportPaneEnv and exportSessionEnv are one exportEnv, telling a child this process's own socket, which a listener's path is from its listen to its deinit; host_io's two calls name it, and forkShell's listener argument, read by nothing now, goes from the frontends' calls with them; the env test sets the socket rather than building a Listener Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/9p_io.zig | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) (limited to 'src/9p_io.zig') diff --git a/src/9p_io.zig b/src/9p_io.zig index 78a08275..8291a37f 100644 --- a/src/9p_io.zig +++ b/src/9p_io.zig @@ -1731,19 +1731,14 @@ pub fn start(io: std.Io, gpa: std.mem.Allocator, core: *pardes.Pardes) ?*Listene /// to reach it, and a `--nested` session exports them too — its socket stays /// open to scripts and to mounted shells — while withholding `PARDES_PID`, /// which is the whole of what `--nested` means. -pub fn exportPaneEnv(listener: ?*const Listener, serial: u32, adopts: bool) void { - exportEnv(if (listener) |l| l.path() else null, serial, adopts); -} - -/// exportPaneEnv for a command run off the loop (an Edit's filter), with -/// this process's own socket: what a pane's command would be given. -pub fn exportSessionEnv(serial: u32, adopts: bool) void { - exportEnv(if (own_socket_len > 0) own_socket[0..own_socket_len] else null, serial, adopts); -} - -/// Told to children through host_io.ChildEnv, never set into this process's -/// own environment (see ChildEnv.exportVar for why). -fn exportEnv(socket: ?[]const u8, serial: u32, adopts: bool) void { +/// +/// The socket is this process's own (`listen` keeps it, its listener's +/// path, until `deinit`), for a pane's shell and for a command run off the +/// loop (an Edit's filter) alike. Told to children through +/// host_io.ChildEnv, never set into this process's own environment (see +/// ChildEnv.exportVar for why). +pub fn exportEnv(serial: u32, adopts: bool) void { + const socket: ?[]const u8 = if (own_socket_len > 0) own_socket[0..own_socket_len] else null; const ChildEnv = @import("host_io.zig").ChildEnv; var pid_buf: [16]u8 = undefined; ChildEnv.exportVar("PARDES_PID", if (adopts) std.fmt.bufPrint(&pid_buf, "{d}", .{@as(u32, @intCast(libc.getpid()))}) catch null else null); @@ -1825,35 +1820,36 @@ test "9P shell environment states being inside pardes apart from how to reach it _ = @import("host_io.zig").testUnsetenv("HOME"); try testing.expect(socketDir(&dir) == null); - const listener = try testing.allocator.create(Listener); - defer testing.allocator.destroy(listener); - listener.* = .{ .io = testing.io, .core = undefined }; // only its path is read + // The socket a listener keeps while it lives. const path = "/tmp/pardes-example.sock"; - @memcpy(listener.path_buf[0..path.len], path); - listener.path_len = path.len; + @memcpy(own_socket[0..path.len], path); + own_socket[path.len] = 0; + own_socket_len = path.len; + defer own_socket_len = 0; var own: [16]u8 = undefined; const own_pid = try std.fmt.bufPrint(&own, "{d}", .{@as(u32, @intCast(libc.getpid()))}); // A `--nested` session: reachable for scripts and mounts, but nobody's // parent, so a pardes started in one of its shells runs a session of // its own instead of handing its argument over. - exportPaneEnv(listener, 7, false); + exportEnv(7, false); try testing.expectEqualStrings(path, @import("host_io.zig").ChildEnv.exported("PARDES_9P").?); try testing.expectEqualStrings("7", @import("host_io.zig").ChildEnv.exported("PARDES_PANE").?); try testing.expect(@import("host_io.zig").ChildEnv.exported("PARDES_PID") == null); - exportPaneEnv(listener, 8, true); + exportEnv(8, true); try testing.expectEqualStrings("8", @import("host_io.zig").ChildEnv.exported("PARDES_PANE").?); try testing.expectEqualStrings(own_pid, @import("host_io.zig").ChildEnv.exported("PARDES_PID").?); // A session whose listener never came up is still the session this shell // is inside: the pid stands on its own, and only the address is missing. - exportPaneEnv(null, 0, true); + own_socket_len = 0; + exportEnv(0, true); try testing.expect(@import("host_io.zig").ChildEnv.exported("PARDES_9P") == null); try testing.expect(@import("host_io.zig").ChildEnv.exported("PARDES_PANE") == null); try testing.expectEqualStrings(own_pid, @import("host_io.zig").ChildEnv.exported("PARDES_PID").?); - exportPaneEnv(null, 0, false); + exportEnv(0, false); try testing.expect(@import("host_io.zig").ChildEnv.exported("PARDES_9P") == null); try testing.expect(@import("host_io.zig").ChildEnv.exported("PARDES_PANE") == null); try testing.expect(@import("host_io.zig").ChildEnv.exported("PARDES_PID") == null); -- cgit v1.3