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

Use libc definitions for wait module #732

Merged
merged 1 commit into from
Aug 25, 2017
Merged

Conversation

Susurrus
Copy link
Contributor

Not certain if these are all correct yet, but we can reuse a ton of logic from libc within the wait module.

src/sys/wait.rs Outdated

pub fn exited(status: i32) -> bool {
(status & 0x7F) == 0
unsafe { libc::WIFEXITED(status) }
Copy link
Member

@asomers asomers Aug 11, 2017

Choose a reason for hiding this comment

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

Why unsafe? libc::WIFEXITED and friends are not FFI functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They're marked as unsafe in libc actually. They're actually also marked as extern "C" which is also interesting. I definitely don't think they need to be either of those. @alexcrichton do you know why this is?

Copy link
Member

Choose a reason for hiding this comment

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

Likely just an oversight. We could move them out of the f! block in libc and then they wouldn't be unsafe anymore. However, I wonder if they even belong in libc at all. There aren't many functions in libc that have more than a simple FFI call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are defined as macros or functions by the spec, so it makes sense to keep them in libc even if they're macros on some platforms and need to be implemented.

Copy link
Contributor

Choose a reason for hiding this comment

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

Everything in libc is automatically extern and unsafe, matching the underlying implementation if it didn't use macros.

@asomers
Copy link
Member

asomers commented Aug 15, 2017

So according to POSIX's definition, these functions may be unsafe, but they happen not to be on all of nix's currently targeted platforms. In that case, libc's decision to make them unsafe everywhere makes sense.

bors r+

bors bot added a commit that referenced this pull request Aug 15, 2017
732: Use libc definitions for wait module r=asomers

Not certain if these are all correct yet, but we can reuse a ton of logic from `libc` within the `wait` module.
@Susurrus
Copy link
Contributor Author

bors r-

@bors
Copy link
Contributor

bors bot commented Aug 15, 2017

Canceled

@Susurrus
Copy link
Contributor Author

Whoops, looking over this again, I think I actually introduced a bug in term_signal. We need to mask off the top bit of the status because of how ptrace works, and I don't think that function does it. I'll check it out tomorrow and see.

@rocallahan
Copy link
Contributor

I think I actually introduced a bug in term_signal

I don't think you did. Linux WTERMSIG masks off bit 7 of the status.

This PR looks good to me, though I think you could go a bit further and eliminate the status module, moving all its functions to the top level.

@Susurrus
Copy link
Contributor Author

@rocallahan Thanks for checking that, yes it does look like it does the right things on Linux.

And I removed the status module, but made all the functions private, as I saw no reason to expose them, especially with the work you're doing in #741.

@Susurrus
Copy link
Contributor Author

bors r+

bors bot added a commit that referenced this pull request Aug 25, 2017
732: Use libc definitions for wait module r=Susurrus a=Susurrus

Not certain if these are all correct yet, but we can reuse a ton of logic from `libc` within the `wait` module.
@bors
Copy link
Contributor

bors bot commented Aug 25, 2017

@bors bors bot merged commit 5967bb1 into nix-rust:master Aug 25, 2017
@Susurrus Susurrus deleted the wait_ffi branch August 25, 2017 16:41
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.

None yet

4 participants