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 3 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
35 changes: 35 additions & 0 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ pub type cc_t = ::c_uchar;
pub enum DIR {}
pub enum locale_t {}

// 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).
cfg_if! {
if #[cfg(target_os = "openbsd")] {
// idtype_t is not available
} else if #[cfg(target_os = "android")] {
pub type idtype_t = ::c_int;
} else {
pub type idtype_t = ::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.

Instead of a cfg_if! block here, could the definition of this just get pushed down into respective modules?

}
}

s! {
pub struct group {
pub gr_name: *mut ::c_char,
Expand Down Expand Up @@ -203,6 +217,22 @@ pub const PRIO_USER: ::c_int = 2;
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")] {
Copy link
Member

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)

// FreeBSD defines a great many more of these, and gives the
// standardized constants different values from everyone else.
pub const P_PID: idtype_t = 0;
pub const P_PGID: idtype_t = 2;
pub const P_ALL: idtype_t = 7;
} else {
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 +477,11 @@ extern {
link_name = "waitpid$UNIX2003")]
pub fn waitpid(pid: pid_t, status: *mut ::c_int, options: ::c_int)
-> pid_t;
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd")))] // " if "
#[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