Skip to content

Commit cb7f667

Browse files
committed
Auto merge of #489 - zackw:add-waitid, r=alexcrichton
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.
2 parents 33ff832 + 84bce94 commit cb7f667

File tree

8 files changed

+80
-0
lines changed

8 files changed

+80
-0
lines changed

src/unix/bsd/apple/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub type tcflag_t = ::c_ulong;
2121
pub type nl_item = ::c_int;
2222
pub type id_t = ::c_uint;
2323
pub type sem_t = ::c_int;
24+
pub type idtype_t = ::c_uint;
2425

2526
pub enum timezone {}
2627

@@ -1365,6 +1366,15 @@ pub const LIO_READ: ::c_int = 1;
13651366
pub const LIO_WAIT: ::c_int = 2;
13661367
pub const LIO_NOWAIT: ::c_int = 1;
13671368

1369+
pub const WEXITED: ::c_int = 0x00000004;
1370+
pub const WSTOPPED: ::c_int = 0x00000008;
1371+
pub const WCONTINUED: ::c_int = 0x00000010;
1372+
pub const WNOWAIT: ::c_int = 0x00000020;
1373+
1374+
pub const P_ALL: idtype_t = 0;
1375+
pub const P_PID: idtype_t = 1;
1376+
pub const P_PGID: idtype_t = 2;
1377+
13681378
f! {
13691379
pub fn WSTOPSIG(status: ::c_int) -> ::c_int {
13701380
status >> 8
@@ -1534,6 +1544,12 @@ extern {
15341544
flags: ::c_int) -> ::c_int;
15351545

15361546
pub fn initgroups(user: *const ::c_char, basegroup: ::c_int) -> ::c_int;
1547+
1548+
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
1549+
link_name = "waitid$UNIX2003")]
1550+
pub fn waitid(idtype: idtype_t, id: id_t, infop: *mut ::siginfo_t,
1551+
options: ::c_int) -> ::c_int;
1552+
15371553
}
15381554

15391555
cfg_if! {

src/unix/bsd/freebsdlike/freebsd/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub type sem_t = _sem;
99

1010
pub type fsblkcnt_t = ::uint64_t;
1111
pub type fsfilcnt_t = ::uint64_t;
12+
pub type idtype_t = ::c_uint;
1213

1314
s! {
1415
pub struct utmpx {
@@ -357,6 +358,18 @@ pub const LC_ALL_MASK: ::c_int = LC_COLLATE_MASK
357358
| LC_NUMERIC_MASK
358359
| LC_TIME_MASK;
359360

361+
pub const WSTOPPED: ::c_int = 2; // same as WUNTRACED
362+
pub const WCONTINUED: ::c_int = 4;
363+
pub const WNOWAIT: ::c_int = 8;
364+
pub const WEXITED: ::c_int = 16;
365+
pub const WTRAPPED: ::c_int = 32;
366+
367+
// FreeBSD defines a great many more of these, we only expose the
368+
// standardized ones.
369+
pub const P_PID: idtype_t = 0;
370+
pub const P_PGID: idtype_t = 2;
371+
pub const P_ALL: idtype_t = 7;
372+
360373
extern {
361374
pub fn __error() -> *mut ::c_int;
362375

@@ -383,6 +396,8 @@ extern {
383396
timeout: *mut ::timespec) -> ::ssize_t;
384397

385398
pub fn freelocale(loc: ::locale_t) -> ::c_int;
399+
pub fn waitid(idtype: idtype_t, id: ::id_t, infop: *mut ::siginfo_t,
400+
options: ::c_int) -> ::c_int;
386401
}
387402

388403
cfg_if! {

src/unix/bsd/netbsdlike/netbsd/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub type dev_t = u64;
44
pub type blksize_t = ::int32_t;
55
pub type fsblkcnt_t = ::uint64_t;
66
pub type fsfilcnt_t = ::uint64_t;
7+
pub type idtype_t = ::c_int;
78

89
s! {
910
pub struct aiocb {
@@ -583,6 +584,15 @@ pub const SIGEV_NONE: ::c_int = 0;
583584
pub const SIGEV_SIGNAL: ::c_int = 1;
584585
pub const SIGEV_THREAD: ::c_int = 2;
585586

587+
pub const WSTOPPED: ::c_int = 0x00000002; // same as WUNTRACED
588+
pub const WCONTINUED: ::c_int = 0x00000010;
589+
pub const WEXITED: ::c_int = 0x000000020;
590+
pub const WNOWAIT: ::c_int = 0x00010000;
591+
592+
pub const P_ALL: idtype_t = 0;
593+
pub const P_PID: idtype_t = 1;
594+
pub const P_PGID: idtype_t = 4;
595+
586596
extern {
587597
pub fn aio_read(aiocbp: *mut aiocb) -> ::c_int;
588598
pub fn aio_write(aiocbp: *mut aiocb) -> ::c_int;

src/unix/haiku/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ pub type fsblkcnt_t = i64;
2828
pub type fsfilcnt_t = i64;
2929
pub type pthread_attr_t = *mut ::c_void;
3030
pub type nl_item = ::c_int;
31+
pub type id_t = i32;
32+
pub type idtype_t = ::c_uint;
3133

3234
pub enum timezone {}
3335

@@ -671,6 +673,17 @@ pub const SO_PEERCRED: ::c_int = 0x4000000b;
671673

672674
pub const NI_MAXHOST: ::size_t = 1025;
673675

676+
pub const WNOHANG: ::c_int = 0x01;
677+
pub const WUNTRACED: ::c_int = 0x02;
678+
pub const WCONTINUED: ::c_int = 0x04;
679+
pub const WEXITED: ::c_int = 0x08;
680+
pub const WSTOPPED: ::c_int = 0x10;
681+
pub const WNOWAIT: ::c_int = 0x20;
682+
683+
pub const P_ALL: idtype_t = 0;
684+
pub const P_PID: idtype_t = 1;
685+
pub const P_PGID: idtype_t = 2;
686+
674687
f! {
675688
pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () {
676689
let fd = fd as usize;
@@ -743,6 +756,8 @@ extern {
743756
flags: ::c_int) -> ::c_int;
744757
pub fn pthread_mutex_timedlock(lock: *mut pthread_mutex_t,
745758
abstime: *const ::timespec) -> ::c_int;
759+
pub fn waitid(idtype: idtype_t, id: id_t, infop: *mut ::siginfo_t,
760+
options: ::c_int) -> ::c_int;
746761
}
747762

748763
cfg_if! {

src/unix/notbsd/android/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub type rlim_t = ::c_ulong;
2525
pub type dev_t = ::c_ulong;
2626
pub type ino_t = ::c_ulong;
2727
pub type __CPU_BITTYPE = ::c_ulong;
28+
pub type idtype_t = ::c_int;
2829

2930
s! {
3031
pub struct dirent {

src/unix/notbsd/linux/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub type msgqnum_t = ::c_ulong;
1717
pub type msglen_t = ::c_ulong;
1818
pub type nfds_t = ::c_ulong;
1919
pub type nl_item = ::c_int;
20+
pub type idtype_t = ::c_uint;
2021

2122
pub enum fpos64_t {} // TODO: fill this out with a struct
2223

src/unix/notbsd/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,10 @@ pub const SIGEV_SIGNAL: ::c_int = 0;
625625
pub const SIGEV_NONE: ::c_int = 1;
626626
pub const SIGEV_THREAD: ::c_int = 2;
627627

628+
pub const P_ALL: idtype_t = 0;
629+
pub const P_PID: idtype_t = 1;
630+
pub const P_PGID: idtype_t = 2;
631+
628632
f! {
629633
pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () {
630634
let fd = fd as usize;
@@ -852,6 +856,8 @@ extern {
852856
buf: *mut ::c_char,
853857
buflen: ::size_t) -> ::c_int;
854858
pub fn clearenv() -> ::c_int;
859+
pub fn waitid(idtype: idtype_t, id: id_t, infop: *mut ::siginfo_t,
860+
options: ::c_int) -> ::c_int;
855861
}
856862

857863
cfg_if! {

src/unix/solaris/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ pub type pthread_key_t = ::c_uint;
3232
pub type blksize_t = u32;
3333
pub type fflags_t = u32;
3434
pub type nl_item = ::c_int;
35+
pub type id_t = ::c_int;
36+
pub type idtype_t = ::c_uint;
3537

3638
pub enum timezone {}
3739

@@ -550,6 +552,18 @@ pub const SIGXFSZ: ::c_int = 31;
550552
pub const WNOHANG: ::c_int = 0x40;
551553
pub const WUNTRACED: ::c_int = 0x04;
552554

555+
pub const WEXITED: ::c_int = 0x01;
556+
pub const WTRAPPED: ::c_int = 0x02;
557+
pub const WSTOPPED: ::c_int = WUNTRACED;
558+
pub const WCONTINUED: ::c_int = 0x08;
559+
pub const WNOWAIT: ::c_int = 0x80;
560+
561+
// Solaris defines a great many more of these; we only expose the
562+
// standardized ones.
563+
pub const P_PID: idtype_t = 0;
564+
pub const P_PGID: idtype_t = 2;
565+
pub const P_ALL: idtype_t = 7;
566+
553567
pub const PROT_NONE: ::c_int = 0;
554568
pub const PROT_READ: ::c_int = 1;
555569
pub const PROT_WRITE: ::c_int = 2;
@@ -1056,4 +1070,6 @@ extern {
10561070
abstime: *const ::timespec) -> ::c_int;
10571071
pub fn pthread_mutex_timedlock(lock: *mut pthread_mutex_t,
10581072
abstime: *const ::timespec) -> ::c_int;
1073+
pub fn waitid(idtype: idtype_t, id: id_t, infop: *mut ::siginfo_t,
1074+
options: ::c_int) -> ::c_int;
10591075
}

0 commit comments

Comments
 (0)