Skip to content
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

Make signal argument to kill optional #445

Merged
merged 1 commit into from
Nov 14, 2016
Merged

Make signal argument to kill optional #445

merged 1 commit into from
Nov 14, 2016

Conversation

fiveop
Copy link
Contributor

@fiveop fiveop commented Oct 24, 2016

Fixes #441

@posborne
Copy link
Member

I feel like a better approach might be to add a new enumerated value rather than making the signal an option. A signal of 0 is still a signal but one that is just handled by the kernel without actually making it to the process.

I'm not sure this signal has an established name (it doesn't appear to in Linux: http://lxr.free-electrons.com/source/arch/arm/include/asm/signal.h?v=2.6.32#L31). I suggest that we just call it SIGZERO.

As an added benefit, this won't break things for users using the existing API.

@fiveop
Copy link
Contributor Author

fiveop commented Oct 25, 2016

I disagree. 0 is no signal, it represents something different. Therefore, it does not belong in the enumeration. I would not have a problem with giving it it's own name, if I not already objected to it belonging to the operation.

Since we break the API left and right at the moment, in order to get things 'nice', I do not have a problem with breaking this. It is easy to adapt code that is affected by the change.

@posborne
Copy link
Member

Although 0 is not implemented as a signal to processes in most operating systems, I am still failing to see a strong reason to separate it. Strace, for instance, goes so far as to name the 0 SIG_0 in its output.

kill(9999, SIG_0)                       = -1 ESRCH (No such process)

@posborne
Copy link
Member

Thinking about this more, I can be OK with the change (better than not having support for this useful operation). Moving forward, we should probably have a push for doing more documentation on our functions, particularly when there are cases like this where things might not be immediately clear from the signature. At present, I would need to read the source (and probably go deep on the man pages) in order to figure out what passing None to this function does.

With some docs added, r=me

@fiveop
Copy link
Contributor Author

fiveop commented Oct 26, 2016

I'll add a documentation comment.

@@ -388,8 +388,12 @@ pub fn pthread_sigmask(how: SigFlags,
Errno::result(res).map(drop)
}

pub fn kill(pid: libc::pid_t, signal: Signal) -> Result<()> {
let res = unsafe { libc::kill(pid, signal as libc::c_int) };
pub fn kill(pid: libc::pid_t, signal: Option<Signal>) -> Result<()> {
Copy link
Member

@kamalmarhubi kamalmarhubi Oct 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can take advantage of the recently added impl<T> From<T> for Option<T>. On recent enough Rust (1.12+), kill(pid, SIGBLAH) will still work, so it's a bit more ergonomic. On earlier Rust, it is equivalent to this change thanks to impl<T> From<T> for T.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I wasn't aware of that change. Nice!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about us supporting Rust (1.7+), though? If someones crate wants to continue to support 1.7+, it has to change its source (which I don't have a problem with in the first place).

So asked differently: Are you saying, that we will passively take advantage of the new impl on new enough Rust versions anyway?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that was my thought. Though perhaps we should wait until we bump minimum version to 1.12, probably in 3-6 months? Not sure how to think about it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to think about it differently: the change from Signal to Option<Signal> is breaking. The change from Option<Signal> to T: Into<Option<Signal>> is (I think?) not breaking thanks to impl<T> From<T> for T. (This depends on how you read "breaking" in signatures.) Our use of the Into<Option<T>> impl would be more akin to "progressive enhancement". A downstream crate requiring its use would have a 1.12+ minimum version, but we would not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case, if making use of the new impl, we should include tests that demonstrate it works in both cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable. And if I understand you and the matter correctly, then we could already use T: Into<Option<Signal>> right now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's my belief!

@fiveop
Copy link
Contributor Author

fiveop commented Nov 5, 2016

@kamalmarhubi better?

@kamalmarhubi
Copy link
Member

Could you add a test to verify that calling it with None works? I want to be sure there's no weird inference stuff that requires us to specify Option::<Signal>::None or something like that. This could even be a no_run doc test, I think.

With that, r=me.

@kamalmarhubi
Copy link
Member

Also I checked and under 1.12 it allows kill(pid, SIGKILL), ie no Some. So that's cool :-)

@fiveop
Copy link
Contributor Author

fiveop commented Nov 14, 2016

@homu r=@kamalmarhubi

@homu
Copy link
Contributor

homu commented Nov 14, 2016

📌 Commit 45d8bee has been approved by @kamalmarhubi

homu added a commit that referenced this pull request Nov 14, 2016
Make signal argument to kill optional

Fixes #441
@homu
Copy link
Contributor

homu commented Nov 14, 2016

⌛ Testing commit 45d8bee with merge 6b26884...

@homu
Copy link
Contributor

homu commented Nov 14, 2016

☀️ Test successful - status

@homu homu merged commit 45d8bee into nix-rust:master Nov 14, 2016
@fiveop fiveop deleted the kill_optional_signal branch January 18, 2017 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants