diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-04 23:51:09 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 09:54:56 -0300 |
| commit | dcb5fede7b5b2ceda0d7015bb8088fa343728378 (patch) | |
| tree | 1266d1054f4b02f2a0786cc0ae53c668c46172f7 /src | |
| parent | 1b311fe309aff2b6b82e4b9e3d865dd8b3cd2077 (diff) | |
| download | pardes-dcb5fede7b5b2ceda0d7015bb8088fa343728378.tar.gz pardes-dcb5fede7b5b2ceda0d7015bb8088fa343728378.zip | |
host_io: ttyCwd, ttyTaken and a test read a process's executable with processExe, and procExe, a Linux-only copy that took a truncated path, goes (on FreeBSD ttyCwd follows a wrapper now, as on Linux)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src')
| -rw-r--r-- | src/host_io.zig | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/src/host_io.zig b/src/host_io.zig index a904f4a4..2b2e1fe3 100644 --- a/src/host_io.zig +++ b/src/host_io.zig @@ -2388,11 +2388,11 @@ pub fn ttyCwd(shell_pid: libc.pid_t, master_fd: c_int, shell_exe: []const u8, bu var exe_buf: [std.fs.max_path_bytes]u8 = undefined; var shell_buf: [std.fs.max_path_bytes]u8 = undefined; const shell = realShell(shell_exe, &shell_buf) orelse return shellCwd(shell_pid, buf); - const exe = procExe(shell_pid, &exe_buf) orelse return shellCwd(shell_pid, buf); + const exe = processExe(shell_pid, &exe_buf) orelse return shellCwd(shell_pid, buf); if (std.mem.eql(u8, exe, shell)) return shellCwd(shell_pid, buf); const fg = tcgetpgrp(master_fd); if (fg <= 0 or fg == shell_pid) return null; - const fg_exe = procExe(fg, &exe_buf) orelse return null; + const fg_exe = processExe(fg, &exe_buf) orelse return null; return if (std.mem.eql(u8, fg_exe, shell)) shellCwd(fg, buf) else null; } @@ -2534,7 +2534,7 @@ pub fn ttyTaken(shell_pid: libc.pid_t, master_fd: c_int) bool { var probe: TtyProbe = undefined; const fg = tcgetpgrp(master_fd); if (fg < 0) return false; - const self_exe = procExe(shell_pid, &probe.self_exe) orelse return false; + const self_exe = processExe(shell_pid, &probe.self_exe) orelse return false; var saw_fg = fg == shell_pid; var pending: usize = 0; @@ -2556,7 +2556,7 @@ pub fn ttyTaken(shell_pid: libc.pid_t, master_fd: c_int) bool { if (g == fg) saw_fg = true; } - const exe = procExe(node.pid, &probe.exe) orelse { + const exe = processExe(node.pid, &probe.exe) orelse { if (offTty(node.pid, &probe.blob)) continue; // Exiting (its exe gone, not a zombie yet), or not ours // to read: outside the foreground group it holds @@ -2996,14 +2996,6 @@ fn readProc(path: [*:0]const u8, buf: []u8) ?[]const u8 { return buf[0..@intCast(got)]; } -fn procExe(pid: libc.pid_t, buf: *[std.fs.max_path_bytes]u8) ?[]const u8 { - var name: [64:0]u8 = undefined; - const link = std.fmt.bufPrintSentinel(&name, "/proc/{d}/exe", .{@as(u32, @intCast(pid))}, 0) catch return null; - const n = libc.readlink(link, buf, buf.len); - if (n <= 0) return null; - return buf[0..@intCast(n)]; -} - fn procPgrp(pid: libc.pid_t, buf: *[4096]u8) ?libc.pid_t { var name: [64:0]u8 = undefined; const path = std.fmt.bufPrintSentinel(&name, "/proc/{d}/stat", .{@as(u32, @intCast(pid))}, 0) catch return null; @@ -3465,8 +3457,8 @@ test "the walk reaches the leaf: bash -c 'sleep 30' takes the tty" { var wrapper_buf: [std.fs.max_path_bytes]u8 = undefined; var shell_buf: [std.fs.max_path_bytes]u8 = undefined; try std.testing.expectEqualStrings( - procExe(sh.pid, &shell_buf).?, - procExe(probe.pending[0].pid, &wrapper_buf).?, + processExe(sh.pid, &shell_buf).?, + processExe(probe.pending[0].pid, &wrapper_buf).?, ); } else { const fg = tcgetpgrp(sh.master); |
