Skip to content

Commit e28cc66

Browse files
committed
w: Fix formatting of command line value
1 parent cd37fba commit e28cc66

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/uu/w/src/w.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,11 @@ fn format_time(time: String) -> Result<String, chrono::format::ParseError> {
140140
}
141141

142142
#[cfg(target_os = "linux")]
143-
fn fetch_cmdline(pid: i32) -> Result<String, std::io::Error> {
143+
fn fetch_cmdline(pid: i32) -> String {
144144
let cmdline_path = Path::new("/proc").join(pid.to_string()).join("cmdline");
145145
fs::read_to_string(cmdline_path)
146+
.unwrap_or_default()
147+
.replace("\0", " ")
146148
}
147149

148150
#[cfg(target_os = "linux")]
@@ -168,7 +170,7 @@ fn fetch_user_info() -> Result<Vec<UserInfo>, std::io::Error> {
168170
idle_time: fetch_idle_time(entry.tty_device())?,
169171
jcpu: format!("{jcpu:.2}"),
170172
pcpu: fetch_pcpu_time(entry.pid()).unwrap_or_default().to_string(),
171-
command: fetch_cmdline(entry.pid()).unwrap_or_default(),
173+
command: fetch_cmdline(entry.pid()),
172174
};
173175
user_info_list.push(user_info);
174176
}

0 commit comments

Comments
 (0)