Repository navigation
pidof: match processes by executable and by rewritten titles #818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
9537be9
0308dbc
cceb09b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -158,3 +158,51 @@ fn test_script() { | |
| executed_via_sh_child.kill().unwrap(); | ||
| executed_via_sh_child.wait().unwrap(); | ||
| } | ||
|
|
||
| #[test] | ||
| #[cfg(target_os = "linux")] | ||
| fn test_process_with_another_argv0() { | ||
| use std::os::unix::process::CommandExt; | ||
|
|
||
| // A copy of the shell under its own name, so the executable and the | ||
| // process name are known. The name is longer than 15 bytes, so the | ||
| // kernel cuts the process name to "pidoftitletest-". | ||
| let temp_dir = tempfile::tempdir().unwrap(); | ||
| let program = temp_dir.path().join("pidoftitletest-long"); | ||
| std::fs::copy("/bin/sh", &program).unwrap(); | ||
|
|
||
| for argv0 in ["pidoftitletest: worker process", "another-argv0"] { | ||
| // "; :" keeps the shell from replacing itself with sleep. Other tests | ||
| // forking while the copy was open for writing make exec fail with | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 0308dbc: the shell now starts in its own process group and the test kills the whole group, so |
||
| // ETXTBSY for a moment, so retry that. | ||
| let mut child = (0..100) | ||
| .find_map(|_| { | ||
| match std::process::Command::new(&program) | ||
| .arg0(argv0) | ||
| .args(["-c", "sleep 5; :"]) | ||
| .process_group(0) | ||
| .spawn() | ||
| { | ||
| Err(e) if e.kind() == std::io::ErrorKind::ExecutableFileBusy => { | ||
| std::thread::sleep(std::time::Duration::from_millis(10)); | ||
| None | ||
| } | ||
| result => Some(result.unwrap()), | ||
| } | ||
| }) | ||
| .unwrap(); | ||
| std::thread::sleep(std::time::Duration::from_millis(200)); | ||
|
|
||
| for name in ["pidoftitletest-long", "pidoftitletest-"] { | ||
| new_ucmd!() | ||
| .arg(name) | ||
| .succeeds() | ||
| .stdout_contains(child.id().to_string()); | ||
| } | ||
| new_ucmd!().arg("pidoftitletest:").fails(); | ||
|
|
||
| // Kill the whole group, so the forked sleep goes too. | ||
| unsafe { uucore::libc::kill(-(child.id() as i32), uucore::libc::SIGKILL) }; | ||
| child.wait().unwrap(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a test for the 15 bytes case
pidoftitletestis 14 bytes so this branch isn't coveredThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 0308dbc: the test binary is now
pidoftitletest-long, and the test checks both the full name and the 15-bytepidoftitletest-the kernel cuts it to.