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

Add waitid and related constants and types. #489

Merged
merged 7 commits into from
Jan 10, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,11 @@ pub const LIO_READ: ::c_int = 1;
pub const LIO_WAIT: ::c_int = 2;
pub const LIO_NOWAIT: ::c_int = 1;

pub const WEXITED: ::c_int = 0x00000004;
pub const WSTOPPED: ::c_int = 0x00000008;
pub const WCONTINUED: ::c_int = 0x00000010;
pub const WNOWAIT: ::c_int = 0x00000020;

f! {
pub fn WSTOPSIG(status: ::c_int) -> ::c_int {
status >> 8
Expand Down
6 changes: 6 additions & 0 deletions src/unix/bsd/freebsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,12 @@ pub const TIOCSWINSZ: ::c_ulong = 0x80087467;

pub const SEM_FAILED: *mut sem_t = 0 as *mut sem_t;

pub const WSTOPPED: ::c_int = 2; // same as WUNTRACED
pub const WCONTINUED: ::c_int = 4;
pub const WNOWAIT: ::c_int = 8;
pub const WEXITED: ::c_int = 16;
pub const WTRAPPED: ::c_int = 32;

f! {
pub fn WSTOPSIG(status: ::c_int) -> ::c_int {
status >> 8
Expand Down
5 changes: 5 additions & 0 deletions src/unix/bsd/netbsdlike/netbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,11 @@ pub const SIGEV_NONE: ::c_int = 0;
pub const SIGEV_SIGNAL: ::c_int = 1;
pub const SIGEV_THREAD: ::c_int = 2;

pub const WSTOPPED: ::c_int = 0x00000002; // same as WUNTRACED
pub const WCONTINUED: ::c_int = 0x00000010;
pub const WEXITED: ::c_int = 0x000000020;
pub const WNOWAIT: ::c_int = 0x00010000;

extern {
pub fn aio_read(aiocbp: *mut aiocb) -> ::c_int;
pub fn aio_write(aiocbp: *mut aiocb) -> ::c_int;
Expand Down
16 changes: 16 additions & 0 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ pub type cc_t = ::c_uchar;
pub enum DIR {}
pub enum locale_t {}

// FIXME: This is technically wrong; 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) and *probably* the underlying type will be
// c_uint everywhere since all of the enumerators are representable by c_uint.
Copy link
Member

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.

Copy link
Contributor Author

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.

pub type idtype_t = ::c_uint;

s! {
pub struct group {
pub gr_name: *mut ::c_char,
Expand Down Expand Up @@ -203,6 +210,10 @@ pub const PRIO_USER: ::c_int = 2;
pub const PRIO_MIN: ::c_int = -20;
pub const PRIO_MAX: ::c_int = 20;

pub const P_ALL: idtype_t = 0;
pub const P_PID: idtype_t = 1;
pub const P_PGID: idtype_t = 2;

cfg_if! {
if #[cfg(dox)] {
// on dox builds don't pull in anything
Expand Down Expand Up @@ -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
Copy link
Member

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]?

Copy link
Contributor Author

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.

#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "waitid$UNIX2003")]
pub fn waitid(idtype: idtype_t, id: id_t, infop: *mut ::siginfo_t,
options: ::c_int) -> ::c_int;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "write$UNIX2003")]
pub fn write(fd: ::c_int, buf: *const ::c_void, count: ::size_t)
Expand Down