Skip to content

add WorkDir column support on macOS - #969

Open
eigenigma wants to merge 2 commits into
dalance:masterfrom
eigenigma:feat/macos-work-dir
Open

add WorkDir column support on macOS#969
eigenigma wants to merge 2 commits into
dalance:masterfrom
eigenigma:feat/macos-work-dir

Conversation

@eigenigma

Copy link
Copy Markdown

libproc's pidcwd() is still a stub on macOS (it always returns Err), so the
column goes through proc_pidinfo(PROC_PIDVNODEPATHINFO) directly. libc already
ships proc_vnodepathinfo, so all that's needed is a #[repr(transparent)]
newtype implementing libproc's PIDInfo, and the column can use the same
pidinfo::<T>() call the rest of process/macos.rs uses. No new dependencies.

The first commit is a small cleanup of work_dir.rs: the Linux and Windows
blocks had identical add() bodies and only differed in how the path is looked
up, so now there's one impl Column and a per-platform
work_dir_of(pid, procfs). No behaviour change, and it drops the
#[allow(dead_code)] on the procfs field. I only have a Mac here, so CI is
the real check for that commit on Linux/Windows.

The lookup happens lazily in add() like the Windows implementation, so nothing
is paid unless the column is actually configured. Other users' processes come
back empty without root, same as the other macOS columns.

Also flips the macOS cell in the README support matrix and adds a CHANGELOG
line.

Tested on macOS 26 / arm64: procs -i WorkDir shows / for system daemons and
the right cwd for my shells, cargo test passes, clippy and fmt are clean (the
remaining warnings are the pre-existing unsafe_op_in_unsafe_fn ones in
process/macos.rs and util.rs).

The Linux block and the Windows block had the same add() body and only
differed in how the path was looked up. Give both a work_dir_of(pid,
procfs) with the same signature and keep a single impl Column. The
procfs field is then read on every platform, so the dead_code allow on
it can go, and the nested if-let ladder on Linux collapses to two lines.

No behaviour change: None and "" already rendered as the same empty
cell.
libproc's pidcwd() is still a stub on macOS that always returns Err, so
this goes through proc_pidinfo(PROC_PIDVNODEPATHINFO) instead. libc
already ships the proc_vnodepathinfo struct; wrapping it in a newtype
that implements libproc's PIDInfo lets the column reuse the same
pidinfo::<T>() path the rest of the macOS code uses. repr(transparent)
is load-bearing there: pidinfo sizes its buffer by size_of::<T>().

The NUL-terminated c_char buffer is converted with util::ptr_to_cstr,
which the FreeBSD columns already use, so its cfg is widened to macOS.

The lookup happens in the column's add() rather than in collect_proc,
same as the Windows implementation, so the extra syscall per process is
only paid when the column is actually shown. Processes owned by other
users come back empty unless running as root, matching how the rest of
the macOS columns behave.
@eigenigma
eigenigma marked this pull request as ready for review September 7, 2026 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant