Skip to content

Commit cd837f7

Browse files
Linux: Correctly handle removed exe link paths
1 parent b5a341d commit cd837f7

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/unix/linux/process.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,20 @@ fn update_proc_info(
481481
// Do not use cmd[0] because it is not the same thing.
482482
// See https://github.com/GuillaumeGomez/sysinfo/issues/697.
483483
p.exe = realpath(proc_path.replace_and_join("exe"));
484+
// If the target executable file was modified or removed, linux appends ` (deleted)` at
485+
// the end. We need to remove it.
486+
// See https://github.com/GuillaumeGomez/sysinfo/issues/1585.
487+
let deleted = b" (deleted)";
488+
if let Some(exe) = &mut p.exe
489+
&& let Some(file_name) = exe.file_name()
490+
&& file_name.as_encoded_bytes().ends_with(deleted)
491+
{
492+
let mut file_name = file_name.as_encoded_bytes().to_vec();
493+
file_name.truncate(file_name.len() - deleted.len());
494+
unsafe {
495+
exe.set_file_name(OsString::from_encoded_bytes_unchecked(file_name));
496+
}
497+
}
484498
}
485499

486500
if refresh_kind.cmd().needs_update(|| p.cmd.is_empty()) {

0 commit comments

Comments
 (0)