diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2025-05-04 00:21:20 +0200 |
|---|---|---|
| committer | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2025-05-04 00:21:20 +0200 |
| commit | deededfb0a99742a4e7cca2464c7f4a6b3d07604 (patch) | |
| tree | 47cd8c3dab006960ef726ffdae0cc473624b4cb6 /core/os | |
| parent | c96d8237ba1dfcc0db455bb8652ea7d8a947f817 (diff) | |
Fix `executable_path` info on Linux
Diffstat (limited to 'core/os')
| -rw-r--r-- | core/os/os2/process_linux.odin | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/core/os/os2/process_linux.odin b/core/os/os2/process_linux.odin index 6d654008b..a0815ca7d 100644 --- a/core/os/os2/process_linux.odin +++ b/core/os/os2/process_linux.odin @@ -200,15 +200,36 @@ _process_info_by_pid :: proc(pid: int, selection: Process_Info_Fields, allocator } if .Executable_Path in selection { - if cmdline[0] == '/' { - info.executable_path = strings.clone(cmdline[:terminator], allocator) or_return + if cwd_err == nil { + info.executable_path = strings.clone(command_line_exec, allocator) or_return + info.fields += {.Executable_Path} + } else { + break cmdline_if + } + /* + NOTE(Jeroen): + + This old version returns the wrong executable path for things like `bash` or `sh`, + for whom `/proc/<pid>/cmdline` will just report "bash" or "sh", + resulting in misleading paths like `$PWD/sh`, even though that executable doesn't exist there. + + A way to "fix" this would be to invoke `which <name>` or scour the $PATH variable, but a better way + would be preferred. + + To be fair, `htop` also suffers from this problem and will list `bash`, `tmux`, `xfce4-panel` as just their + executable name in the command line column. So I think we shouldn't prepend the current directory when an executable is + found in the $PATH, which is what seems to be happening here. + + if command_line_exec[0] == '/' { + info.executable_path = strings.clone(command_line_exec, allocator) or_return info.fields += {.Executable_Path} } else if cwd_err == nil { - info.executable_path = join_path({ cwd, cmdline[:terminator] }, allocator) or_return + info.executable_path = join_path({cwd, command_line_exec}, allocator) or_return info.fields += {.Executable_Path} } else { break cmdline_if } + */ } if selection & {.Command_Line, .Command_Args} != {} { |