Skip to content

Commit 31d9779

Browse files
committed
Reorganize again; more portability fixes.
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'.
1 parent f1a91da commit 31d9779

File tree

8 files changed

+108
-41
lines changed

8 files changed

+108
-41
lines changed

src/unix/bsd/apple/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ pub type nl_item = ::c_int;
2222
pub type id_t = ::c_uint;
2323
pub type sem_t = ::c_int;
2424

25+
// idtype_t is specified as a C enum:
26+
// http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_wait.h.html
27+
// However, FFI doesn't currently know how to ABI-match a C enum
28+
// (rust#28925, rust#34641).
29+
pub type idtype_t = ::c_uint;
30+
2531
pub enum timezone {}
2632

2733
s! {
@@ -1368,6 +1374,10 @@ pub const WSTOPPED: ::c_int = 0x00000008;
13681374
pub const WCONTINUED: ::c_int = 0x00000010;
13691375
pub const WNOWAIT: ::c_int = 0x00000020;
13701376

1377+
pub const P_ALL: idtype_t = 0;
1378+
pub const P_PID: idtype_t = 1;
1379+
pub const P_PGID: idtype_t = 2;
1380+
13711381
f! {
13721382
pub fn WSTOPSIG(status: ::c_int) -> ::c_int {
13731383
status >> 8
@@ -1537,6 +1547,12 @@ extern {
15371547
flags: ::c_int) -> ::c_int;
15381548

15391549
pub fn initgroups(user: *const ::c_char, basegroup: ::c_int) -> ::c_int;
1550+
1551+
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
1552+
link_name = "waitid$UNIX2003")]
1553+
pub fn waitid(idtype: idtype_t, id: id_t, infop: *mut ::siginfo_t,
1554+
options: ::c_int) -> ::c_int;
1555+
15401556
}
15411557

15421558
cfg_if! {

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

+20
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ pub type sem_t = _sem;
1010
pub type fsblkcnt_t = ::uint64_t;
1111
pub type fsfilcnt_t = ::uint64_t;
1212

13+
// idtype_t is specified as a C enum:
14+
// http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_wait.h.html
15+
// However, FFI doesn't currently know how to ABI-match a C enum
16+
// (rust#28925, rust#34641).
17+
pub type idtype_t = ::c_uint;
18+
1319
s! {
1420
pub struct utmpx {
1521
pub ut_type: ::c_short,
@@ -356,6 +362,18 @@ pub const LC_ALL_MASK: ::c_int = LC_COLLATE_MASK
356362
| LC_NUMERIC_MASK
357363
| LC_TIME_MASK;
358364

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

@@ -382,6 +400,8 @@ extern {
382400
timeout: *mut ::timespec) -> ::ssize_t;
383401

384402
pub fn freelocale(loc: ::locale_t) -> ::c_int;
403+
pub fn waitid(idtype: idtype_t, id: id_t, infop: *mut ::siginfo_t,
404+
options: ::c_int) -> ::c_int;
385405
}
386406

387407
cfg_if! {

src/unix/bsd/freebsdlike/mod.rs

-6
Original file line numberDiff line numberDiff line change
@@ -693,12 +693,6 @@ pub const TIOCSWINSZ: ::c_ulong = 0x80087467;
693693

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

696-
pub const WSTOPPED: ::c_int = 2; // same as WUNTRACED
697-
pub const WCONTINUED: ::c_int = 4;
698-
pub const WNOWAIT: ::c_int = 8;
699-
pub const WEXITED: ::c_int = 16;
700-
pub const WTRAPPED: ::c_int = 32;
701-
702696
f! {
703697
pub fn WSTOPSIG(status: ::c_int) -> ::c_int {
704698
status >> 8

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

+15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ pub type blksize_t = ::int32_t;
55
pub type fsblkcnt_t = ::uint64_t;
66
pub type fsfilcnt_t = ::uint64_t;
77

8+
// idtype_t is specified as a C enum:
9+
// http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_wait.h.html
10+
// However, FFI doesn't currently know how to ABI-match a C enum
11+
// (rust#28925, rust#34641).
12+
pub type idtype_t = ::c_int;
13+
814
s! {
915
pub struct aiocb {
1016
pub aio_offset: ::off_t,
@@ -588,6 +594,10 @@ pub const WCONTINUED: ::c_int = 0x00000010;
588594
pub const WEXITED: ::c_int = 0x000000020;
589595
pub const WNOWAIT: ::c_int = 0x00010000;
590596

597+
pub const P_ALL: idtype_t = 0;
598+
pub const P_PID: idtype_t = 1;
599+
pub const P_PGID: idtype_t = 4;
600+
591601
extern {
592602
pub fn aio_read(aiocbp: *mut aiocb) -> ::c_int;
593603
pub fn aio_write(aiocbp: *mut aiocb) -> ::c_int;
@@ -663,6 +673,11 @@ extern {
663673
pub fn newlocale(mask: ::c_int,
664674
locale: *const ::c_char,
665675
base: ::locale_t) -> ::locale_t;
676+
677+
// This should work, but it causes the netbsd CI build to fail with an
678+
// intra-libc.a undefined reference to `wait6`.
679+
//pub fn waitid(idtype: idtype_t, id: id_t, infop: *mut ::siginfo_t,
680+
// options: ::c_int) -> ::c_int;
666681
}
667682

668683
mod other;

src/unix/haiku/mod.rs

+19
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ pub type fsfilcnt_t = i64;
2929
pub type pthread_attr_t = *mut ::c_void;
3030
pub type nl_item = ::c_int;
3131

32+
// idtype_t is specified as a C enum:
33+
// http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_wait.h.html
34+
// However, FFI doesn't currently know how to ABI-match a C enum
35+
// (rust#28925, rust#34641).
36+
pub type idtype_t = ::c_uint;
37+
3238
pub enum timezone {}
3339

3440
s! {
@@ -670,6 +676,17 @@ pub const SO_PEERCRED: ::c_int = 0x4000000b;
670676

671677
pub const NI_MAXHOST: ::size_t = 1025;
672678

679+
pub const WNOHANG: ::c_int = 0x01;
680+
pub const WUNTRACED: ::c_int = 0x02;
681+
pub const WCONTINUED: ::c_int = 0x04;
682+
pub const WEXITED: ::c_int = 0x08;
683+
pub const WSTOPPED: ::c_int = 0x10;
684+
pub const WNOWAIT: ::c_int = 0x20;
685+
686+
pub const P_ALL: idtype_t = 0;
687+
pub const P_PID: idtype_t = 1;
688+
pub const P_PGID: idtype_t = 2;
689+
673690
f! {
674691
pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () {
675692
let fd = fd as usize;
@@ -742,6 +759,8 @@ extern {
742759
flags: ::c_int) -> ::c_int;
743760
pub fn pthread_mutex_timedlock(lock: *mut pthread_mutex_t,
744761
abstime: *const ::timespec) -> ::c_int;
762+
pub fn waitid(idtype: idtype_t, id: id_t, infop: *mut ::siginfo_t,
763+
options: ::c_int) -> ::c_int;
745764
}
746765

747766
cfg_if! {

src/unix/mod.rs

-35
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,6 @@ pub type cc_t = ::c_uchar;
1616
pub enum DIR {}
1717
pub enum locale_t {}
1818

19-
// idtype_t is specified as a C enum:
20-
// http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_wait.h.html
21-
// However, FFI doesn't currently know how to ABI-match a C enum
22-
// (rust#28925, rust#34641).
23-
cfg_if! {
24-
if #[cfg(target_os = "openbsd")] {
25-
// idtype_t is not available
26-
} else if #[cfg(target_os = "android")] {
27-
pub type idtype_t = ::c_int;
28-
} else {
29-
pub type idtype_t = ::c_uint;
30-
}
31-
}
32-
3319
s! {
3420
pub struct group {
3521
pub gr_name: *mut ::c_char,
@@ -217,22 +203,6 @@ pub const PRIO_USER: ::c_int = 2;
217203
pub const PRIO_MIN: ::c_int = -20;
218204
pub const PRIO_MAX: ::c_int = 20;
219205

220-
cfg_if! {
221-
if #[cfg(target_os = "openbsd")] {
222-
// P_* constants are not available
223-
} else if #[cfg(target_os = "freebsd")] {
224-
// FreeBSD defines a great many more of these, and gives the
225-
// standardized constants different values from everyone else.
226-
pub const P_PID: idtype_t = 0;
227-
pub const P_PGID: idtype_t = 2;
228-
pub const P_ALL: idtype_t = 7;
229-
} else {
230-
pub const P_ALL: idtype_t = 0;
231-
pub const P_PID: idtype_t = 1;
232-
pub const P_PGID: idtype_t = 2;
233-
}
234-
}
235-
236206
cfg_if! {
237207
if #[cfg(dox)] {
238208
// on dox builds don't pull in anything
@@ -477,11 +447,6 @@ extern {
477447
link_name = "waitpid$UNIX2003")]
478448
pub fn waitpid(pid: pid_t, status: *mut ::c_int, options: ::c_int)
479449
-> pid_t;
480-
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd")))] // " if "
481-
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
482-
link_name = "waitid$UNIX2003")]
483-
pub fn waitid(idtype: idtype_t, id: id_t, infop: *mut ::siginfo_t,
484-
options: ::c_int) -> ::c_int;
485450
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
486451
link_name = "write$UNIX2003")]
487452
pub fn write(fd: ::c_int, buf: *const ::c_void, count: ::size_t)

src/unix/notbsd/mod.rs

+18
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ pub type clockid_t = ::c_int;
99
pub type key_t = ::c_int;
1010
pub type id_t = ::c_uint;
1111

12+
// idtype_t is specified as a C enum:
13+
// http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_wait.h.html
14+
// However, FFI doesn't currently know how to ABI-match a C enum
15+
// (rust#28925, rust#34641).
16+
cfg_if! {
17+
if #[cfg(target_os = "android")] {
18+
pub type idtype_t = ::c_int;
19+
} else {
20+
pub type idtype_t = ::c_uint;
21+
}
22+
}
23+
1224
pub enum timezone {}
1325

1426
s! {
@@ -624,6 +636,10 @@ pub const SIGEV_SIGNAL: ::c_int = 0;
624636
pub const SIGEV_NONE: ::c_int = 1;
625637
pub const SIGEV_THREAD: ::c_int = 2;
626638

639+
pub const P_ALL: idtype_t = 0;
640+
pub const P_PID: idtype_t = 1;
641+
pub const P_PGID: idtype_t = 2;
642+
627643
f! {
628644
pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () {
629645
let fd = fd as usize;
@@ -851,6 +867,8 @@ extern {
851867
buf: *mut ::c_char,
852868
buflen: ::size_t) -> ::c_int;
853869
pub fn clearenv() -> ::c_int;
870+
pub fn waitid(idtype: idtype_t, id: id_t, infop: *mut ::siginfo_t,
871+
options: ::c_int) -> ::c_int;
854872
}
855873

856874
cfg_if! {

src/unix/solaris/mod.rs

+20
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ pub type blksize_t = u32;
3333
pub type fflags_t = u32;
3434
pub type nl_item = ::c_int;
3535

36+
// idtype_t is specified as a C enum:
37+
// http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_wait.h.html
38+
// However, FFI doesn't currently know how to ABI-match a C enum
39+
// (rust#28925, rust#34641).
40+
pub type idtype_t = ::c_uint;
41+
3642
pub enum timezone {}
3743

3844
s! {
@@ -550,6 +556,18 @@ pub const SIGXFSZ: ::c_int = 31;
550556
pub const WNOHANG: ::c_int = 0x40;
551557
pub const WUNTRACED: ::c_int = 0x04;
552558

559+
pub const WEXITED: ::c_int = 0x01;
560+
pub const WTRAPPED: ::c_int = 0x02;
561+
pub const WSTOPPED: ::c_int = WUNTRACED;
562+
pub const WCONTINUED: ::c_int = 0x08;
563+
pub const WNOWAIT: ::c_int = 0x80;
564+
565+
// Solaris defines a great many more of these; we only expose the
566+
// standardized ones.
567+
pub const P_PID: idtype_t = 0;
568+
pub const P_PGID: idtype_t = 2;
569+
pub const P_ALL: idtype_t = 7;
570+
553571
pub const PROT_NONE: ::c_int = 0;
554572
pub const PROT_READ: ::c_int = 1;
555573
pub const PROT_WRITE: ::c_int = 2;
@@ -1056,4 +1074,6 @@ extern {
10561074
abstime: *const ::timespec) -> ::c_int;
10571075
pub fn pthread_mutex_timedlock(lock: *mut pthread_mutex_t,
10581076
abstime: *const ::timespec) -> ::c_int;
1077+
pub fn waitid(idtype: idtype_t, id: id_t, infop: *mut ::siginfo_t,
1078+
options: ::c_int) -> ::c_int;
10591079
}

0 commit comments

Comments
 (0)