diff --git a/src/uu/w/src/w.rs b/src/uu/w/src/w.rs index 88e2ad85..91adbb10 100644 --- a/src/uu/w/src/w.rs +++ b/src/uu/w/src/w.rs @@ -142,7 +142,8 @@ fn format_time(time: String) -> Result { #[cfg(target_os = "linux")] fn fetch_cmdline(pid: i32) -> Result { let cmdline_path = Path::new("/proc").join(pid.to_string()).join("cmdline"); - fs::read_to_string(cmdline_path) + // See `proc_pid_cmdline(5)` man page for the format of /proc//cmdline + fs::read_to_string(cmdline_path).map(|s| s.trim_end_matches('\0').replace('\0', " ")) } #[cfg(target_os = "linux")] @@ -452,11 +453,8 @@ mod tests { fn test_fetch_cmdline() { // uucore's utmpx returns an i32, so we cast to that to mimic it. let pid = process::id() as i32; - let path = Path::new("/proc").join(pid.to_string()).join("cmdline"); - assert_eq!( - fs::read_to_string(path).unwrap(), - fetch_cmdline(pid).unwrap() - ); + let cmdline = std::env::args().collect::>().join(" "); + assert_eq!(cmdline, fetch_cmdline(pid).unwrap()); } #[test]