-
Notifications
You must be signed in to change notification settings - Fork 666
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
Add killpg #1034
Add killpg #1034
Conversation
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.
This needs documentation and tests, too.
let res = unsafe { libc::killpg(pid.into(), | ||
match signal.into() { | ||
Some(s) => s as libc::c_int, | ||
None => 0, |
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.
Why would you ever want to send 0? Is that even valid?
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.
It's valid. It just perform error checking and won't send any signal.
According to the POSIX spec of killpg
:
If pgrp is greater than 1, killpg(pgrp, sig) shall be equivalent to kill(-pgrp, sig).
And in the POSIX spec of kill
:
The signal to be sent is specified by sig and is either one from the list given in <signal.h> or 0. If sig is 0 (the null signal), error checking is performed but no signal is actually sent. The null signal can be used to check the validity of pid.
Also in the manpage of killpg
:
On Linux, killpg() is implemented as a library function that makes the call kill(-pgrp, sig).
Thanks for reviewing. Actually I just copy the implement of |
@asomers I have added test & document. Can you review again please? |
@@ -680,6 +680,8 @@ pub fn kill<T: Into<Option<Signal>>>(pid: ::unistd::Pid, signal: T) -> Result<() | |||
Errno::result(res).map(drop) | |||
} | |||
|
|||
/// Send a signal to a process group [(see | |||
/// killpg(3))](http://pubs.opengroup.org/onlinepubs/9699919799/functions/killpg.html). |
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.
The docs should say what the arguments mean. It's not obvious why signal
should be an Option
. Also, I see from the man page that killpg
does something special when pgrp
is 0. Perhaps that should be an option too?
test/sys/test_signal.rs
Outdated
@@ -9,6 +9,11 @@ fn test_kill_none() { | |||
kill(getpid(), None).expect("Should be able to send signal to myself."); | |||
} | |||
|
|||
#[test] | |||
fn test_killpg_none() { | |||
killpg(getpgrp(), None).expect("Should be able to send signal to my process group."); |
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.
80 columns, please.
@asomers I have update the document. Can you check again? |
src/sys/signal.rs
Outdated
/// Send a signal to a process group [(see | ||
/// killpg(3))](http://pubs.opengroup.org/onlinepubs/9699919799/functions/killpg.html). | ||
/// | ||
/// If `pgrp` less then or equal 1, the behavior is undefined. |
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.
In compiler-speak, "Undefined behavior" means something specific and very bad. It would be better to say "platform-specific".
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.
@asomers OK. I have updated it.
Ok, looks good. It just needs a squash now. |
Thanks again. I just squashed all commits. |
Ahh, it looks like the PR I merged yesterday now conflicts with your CHANGELOG entry. I'm afraid you'll have to rebase. |
OK. I think I fixed it. |
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.
bors r+
1034: Add killpg r=asomers a=DanSnow It's seem that #644 is inactively about 1 year. But I really want this API that can land in nix. Actually I not really understand how to check the availability of an API for other platform except Linux. But I saw that this API in `libc` is wrapping inside a `#[cfg(unix)]`. So I don't need to add any `#[cfg]` on this API, am I right? Resolved #644 Co-authored-by: DanSnow <dododavid006@gmail.com>
Build succeeded
|
It's seem that #644 is inactively about 1 year. But I really want this API that can land in nix.
Actually I not really understand how to check the availability of an API for other platform except Linux. But I saw that this API in
libc
is wrapping inside a#[cfg(unix)]
. So I don't need to add any#[cfg]
on this API, am I right?Resolved #644