-
Notifications
You must be signed in to change notification settings - Fork 1k
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 waitid and related constants and types. #489
Conversation
waitid() is a variation on waitpid() with a marginally more convenient way of reporting the status, and a couple of handy additional features, such as the ability to peek at an exit status without consuming it. It's in POSIX.1-2008 and should be available on all supported Unixes. Along with it come the type 'idtype_t' and the constants WEXITED, WSTOPPED, WCONTINUED, and WNOWAIT. Theconstants were alre dy defined for unix/notbsd platforms. Patch incomplete: several targets are going to have to add definitions of siginfo_t, but I'm not sure which ones yet.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Nice! We tend to avoid literal |
@alexcrichton The trouble is that |
Sure yeah, but C enums are different than Rust enums, they're extensible. |
* idtype_t no longer an enum. * Darwin/x86-32 needs the $UNIX2003 thing. * Darwin, FreeBSD, and NetBSD all have different values for the new constants. * OpenBSD doesn't have this feature at all. (Hopefully we can get away with defining idtype_t anyway.)
@@ -447,6 +458,11 @@ extern { | |||
link_name = "waitpid$UNIX2003")] | |||
pub fn waitpid(pid: pid_t, status: *mut ::c_int, options: ::c_int) | |||
-> pid_t; | |||
#[cfg(not(target_os = "openbsd"))] // " if " -- appease style checker |
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.
Could the definition here be pushed down into the various modules to avoid the #[cfg]
?
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.
Can we defer that conversation until after I have something that works everywhere, please? I don't think the right tradeoff among tidiness, consistency with other stuff, and minimization of repetition will be apparent till then.
// [ http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_wait.h.html ] | ||
// However, FFI doesn't currently know how to ABI-match a C enum | ||
// (rust#28925, rust#34641) and *probably* the underlying type will be | ||
// c_uint everywhere since all of the enumerators are representable by c_uint. |
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.
I think it's ok to remove this FIXME, I don't think it's possible to fix such a fixme.
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 the new rev, it still says this, but not as a FIXME. I think it's valuable to document that we are manually matching a C enum here. Especially as, it turns out, the underlying type differs on Android.
* OpenBSD doesn't have idtype_t or the P_* constants either * FreeBSD has different values for the P_* constants * Android gives idtype_t a different signedness * Disable waitid on NetBSD as it causes a link failure - I think this may be a problem with the test environment
} else if #[cfg(target_os = "android")] { | ||
pub type idtype_t = ::c_int; | ||
} else { | ||
pub type idtype_t = ::c_uint; |
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.
Instead of a cfg_if!
block here, could the definition of this just get pushed down into respective modules?
@@ -204,6 +218,22 @@ pub const PRIO_MIN: ::c_int = -20; | |||
pub const PRIO_MAX: ::c_int = 20; | |||
|
|||
cfg_if! { | |||
if #[cfg(target_os = "openbsd")] { | |||
// P_* constants are not available | |||
} else if #[cfg(target_os = "freebsd")] { |
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.
Similar to above, could this cfg_if!
be avoided to push the definitions into lower modules? (duplication is fine)
@zackw oh if you're writing for a green bill of health on Travis before worrying about organization no worries! Feel free to just ping me when it's all working and I'll come take a look at the style. |
It turns out that *only* FreeBSD and NetBSD proper have waitid, and that Solaris' additional W* constants are totally different from everyone else's, which tips me over from 'find some way to shoehorn this into the top-level unix/mod.rs' to 'put it in the submodules, live with the code duplication'.
@alexcrichton This is ready to be reviewed now. I did wind up pushing stuff down into submodules - the cross-platform variance is bigger than I thought it was. You probably want to look only at the diff versus master; let me know if you want a squashed version. There's still a weird problem with NetBSD (which is why the actual function prototype is commented out in that file), and I'm a little surprised not to have had to add any definitions of |
// idtype_t is specified as a C enum: | ||
// http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_wait.h.html | ||
// However, FFI doesn't currently know how to ABI-match a C enum | ||
// (rust#28925, rust#34641). |
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 ok to avoid repeating this comment in all locations, we tend to not have a lot of comments in libc due to the large amount of duplication.
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.
Hm, the trouble is that there isn't an obvious "top" or "first" place to put it. I think I'll leave it in bsd/apple/mod.rs, which is alphabetically first, and remove it from the others; does that sound good?
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.
Oh I think it's safe to just elide the comment in general. All the relevant properties of the typedef are already checked against the C representation, so it's basically never going to change, so it's ok to omit the comment.
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.
OK, done.
// This should work, but it causes the netbsd CI build to fail with an | ||
// intra-libc.a undefined reference to `wait6`. | ||
//pub fn waitid(idtype: idtype_t, id: id_t, infop: *mut ::siginfo_t, | ||
// options: ::c_int) -> ::c_int; |
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 may just need a #[link_name]
of some form, but otherwise it's ok to just delete this for now.
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.
Yeah, OK. To be clear, though, I'm pretty sure this is a bug within (possibly just the rumprun version of) NetBSD libc. The actual error is
/usr/local/rumprun-x86_64/lib/libc.a(waitid.o): In function `_waitid':
/build/rumprun/src-netbsd/lib/libc/gen/waitid.c:52: undefined reference to `wait6'
I don't think there's any way to work around that from within our code.
// (rust#28925, rust#34641). | ||
cfg_if! { | ||
if #[cfg(target_os = "android")] { | ||
pub type idtype_t = ::c_int; |
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.
Can this be pushed into the two lower modules as well to avoid the cfg_if!
?
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.
Sure.
So I think this is fully baked now; do you want it rebased and squashed? |
@bors: r+ Thanks! |
📌 Commit 84bce94 has been approved by |
Add waitid and related constants and types. [`waitid`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/waitid.html) is a variation on `waitpid` with a marginally more convenient way of reporting the status, and a couple of handy additional features, such as the ability to peek at an exit status without consuming it. It's in POSIX.1-2008 and should be available on all supported Unixes. Along with it come the type `idtype_t` and the constants `WEXITED`, `WSTOPPED`, `WCONTINUED`, and `WNOWAIT`. The constants were already defined for unix/notbsd platforms. The patch is currently incomplete: I'm pushing it to get CI to test platforms I don't have. Todo list is * [x] Add a definition of `siginfo_t` to all platforms that don't have it. * [x] Verify that the new constants are consistent for all \*BSD platforms. * [x] Verify that `idtype_t` is consistent across the board. * [x] Add `link_name` annotations for `waitid` if/as necessary.
Nah it's ok, we can go ahead and merge if CI passes |
💔 Test failed - status-travis |
@bors: retry
* network errors
…On Tue, Jan 10, 2017 at 11:20 AM, bors ***@***.***> wrote:
💔 Test failed - status-travis
<https://travis-ci.org/rust-lang/libc/builds/190697657>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#489 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAD95JLbP4jsdoLgx3QFNCAeNjfEv4paks5rQ9nhgaJpZM4Lc6Re>
.
|
Add waitid and related constants and types. [`waitid`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/waitid.html) is a variation on `waitpid` with a marginally more convenient way of reporting the status, and a couple of handy additional features, such as the ability to peek at an exit status without consuming it. It's in POSIX.1-2008 and should be available on all supported Unixes. Along with it come the type `idtype_t` and the constants `WEXITED`, `WSTOPPED`, `WCONTINUED`, and `WNOWAIT`. The constants were already defined for unix/notbsd platforms. The patch is currently incomplete: I'm pushing it to get CI to test platforms I don't have. Todo list is * [x] Add a definition of `siginfo_t` to all platforms that don't have it. * [x] Verify that the new constants are consistent for all \*BSD platforms. * [x] Verify that `idtype_t` is consistent across the board. * [x] Add `link_name` annotations for `waitid` if/as necessary.
☀️ Test successful - status-appveyor, status-travis |
Fix ControlMessage::encode_into when encoding multiple messages copy_bytes updates dst so that it points after the bytes that were just copied into it. encode_into did not advance the buffer in the same way when encoding the data. See rust-lang#473
waitid
is a variation onwaitpid
with a marginally more convenient way of reporting the status, and a couple of handyadditional features, such as the ability to peek at an exit status without consuming it. It's in POSIX.1-2008 and should be available on all supported Unixes.
Along with it come the type
idtype_t
and the constantsWEXITED
,WSTOPPED
,WCONTINUED
, andWNOWAIT
. The constants were already defined for unix/notbsd platforms.The patch is currently incomplete: I'm pushing it to get CI to test platforms I don't have. Todo list is
siginfo_t
to all platforms that don't have it.idtype_t
is consistent across the board.link_name
annotations forwaitid
if/as necessary.