diff options
Diffstat (limited to 'src/host_io.zig')
| -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); |
