Skip to content

Commit 5e6db09

Browse files
committed
Remove more unsupported functions and make it possible to run tests
1 parent 034cca6 commit 5e6db09

14 files changed

+80
-27
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ name = "test-mount"
5353
path = "test/test_mount.rs"
5454
harness = false
5555

56-
[[test]]
56+
[[target.'cfg(not(target_os = "redox"))'.test]]
5757
name = "test-ptymaster-drop"
5858
path = "test/test_ptymaster_drop.rs"

src/dir.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
1+
#[cfg(not(target_os = "redox"))]
12
use {Error, NixPath, Result};
3+
#[cfg(not(target_os = "redox"))]
24
use errno::Errno;
5+
#[cfg(not(target_os = "redox"))]
36
use fcntl::{self, OFlag};
47
use libc;
5-
use std::os::unix::io::{IntoRawFd, RawFd};
68
#[cfg(not(target_os = "redox"))]
7-
use std::os::unix::io::AsRawFd;
8-
use std::{ffi, ptr};
9+
use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};
10+
#[cfg(not(target_os = "redox"))]
11+
use std::ptr;
12+
use std::ffi;
13+
#[cfg(not(target_os = "redox"))]
914
use sys;
1015

1116
#[cfg(target_os = "linux")]
1217
use libc::{dirent64 as dirent, readdir64_r as readdir_r};
1318

14-
#[cfg(not(target_os = "linux"))]
19+
#[cfg(target_os = "redox")]
20+
use libc::dirent;
21+
22+
#[cfg(not(any(target_os = "linux", target_os = "redox")))]
1523
use libc::{dirent, readdir_r};
1624

1725
/// An open directory.
@@ -28,10 +36,12 @@ use libc::{dirent, readdir_r};
2836
/// * returns entries' names as a `CStr` (no allocation or conversion beyond whatever libc
2937
/// does).
3038
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
39+
#[cfg(not(target_os = "redox"))]
3140
pub struct Dir(
3241
ptr::NonNull<libc::DIR>
3342
);
3443

44+
#[cfg(not(target_os = "redox"))]
3545
impl Dir {
3646
/// Opens the given path as with `fcntl::open`.
3747
pub fn open<P: ?Sized + NixPath>(path: &P, oflag: OFlag,
@@ -77,6 +87,7 @@ impl Dir {
7787
// call `readdir` simultaneously from multiple threads.
7888
//
7989
// `Dir` is safe to pass from one thread to another, as it's not reference-counted.
90+
#[cfg(not(target_os = "redox"))]
8091
unsafe impl Send for Dir {}
8192

8293
#[cfg(not(target_os = "redox"))]
@@ -86,15 +97,18 @@ impl AsRawFd for Dir {
8697
}
8798
}
8899

100+
#[cfg(not(target_os = "redox"))]
89101
impl Drop for Dir {
90102
fn drop(&mut self) {
91103
unsafe { libc::closedir(self.0.as_ptr()) };
92104
}
93105
}
94106

95107
#[derive(Debug, Eq, Hash, PartialEq)]
108+
#[cfg(not(target_os = "redox"))]
96109
pub struct Iter<'d>(&'d mut Dir);
97110

111+
#[cfg(not(target_os = "redox"))]
98112
impl<'d> Iterator for Iter<'d> {
99113
type Item = Result<Entry>;
100114

@@ -119,6 +133,7 @@ impl<'d> Iterator for Iter<'d> {
119133
}
120134
}
121135

136+
#[cfg(not(target_os = "redox"))]
122137
impl<'d> Drop for Iter<'d> {
123138
fn drop(&mut self) {
124139
unsafe { libc::rewinddir((self.0).0.as_ptr()) }

src/fcntl.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ pub fn open<P: ?Sized + NixPath>(path: &P, oflag: OFlag, mode: Mode) -> Result<R
165165
Errno::result(fd)
166166
}
167167

168+
#[cfg(not(target_os = "redox"))]
168169
pub fn openat<P: ?Sized + NixPath>(dirfd: RawFd, path: &P, oflag: OFlag, mode: Mode) -> Result<RawFd> {
169170
let fd = path.with_nix_path(|cstr| {
170171
unsafe { libc::openat(dirfd, cstr.as_ptr(), oflag.bits(), mode.bits() as c_uint) }
@@ -194,6 +195,7 @@ pub fn readlink<'a, P: ?Sized + NixPath>(path: &P, buffer: &'a mut [u8]) -> Resu
194195
}
195196

196197

198+
#[cfg(not(target_os = "redox"))]
197199
pub fn readlinkat<'a, P: ?Sized + NixPath>(dirfd: RawFd, path: &P, buffer: &'a mut [u8]) -> Result<&'a OsStr> {
198200
let res = path.with_nix_path(|cstr| {
199201
unsafe { libc::readlinkat(dirfd, cstr.as_ptr(), buffer.as_mut_ptr() as *mut c_char, buffer.len() as size_t) }

src/sys/signal.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ impl SigSet {
452452

453453
/// Suspends execution of the calling thread until one of the signals in the
454454
/// signal mask becomes pending, and returns the accepted signal.
455+
#[cfg(not(target_os = "redox"))]
455456
pub fn wait(&self) -> Result<Signal> {
456457
let mut signum: libc::c_int = unsafe { mem::uninitialized() };
457458
let res = unsafe { libc::sigwait(&self.sigset as *const libc::sigset_t, &mut signum) };
@@ -863,6 +864,7 @@ mod sigevent {
863864

864865
#[cfg(test)]
865866
mod tests {
867+
#[cfg(not(target_os = "redox"))]
866868
use std::thread;
867869
use super::*;
868870

@@ -918,6 +920,7 @@ mod tests {
918920
}
919921

920922
#[test]
923+
#[cfg(not(target_os = "redox"))]
921924
fn test_thread_signal_set_mask() {
922925
thread::spawn(|| {
923926
let prev_mask = SigSet::thread_get_mask()
@@ -938,6 +941,7 @@ mod tests {
938941
}
939942

940943
#[test]
944+
#[cfg(not(target_os = "redox"))]
941945
fn test_thread_signal_block() {
942946
thread::spawn(|| {
943947
let mut mask = SigSet::empty();
@@ -950,6 +954,7 @@ mod tests {
950954
}
951955

952956
#[test]
957+
#[cfg(not(target_os = "redox"))]
953958
fn test_thread_signal_unblock() {
954959
thread::spawn(|| {
955960
let mut mask = SigSet::empty();
@@ -962,6 +967,7 @@ mod tests {
962967
}
963968

964969
#[test]
970+
#[cfg(not(target_os = "redox"))]
965971
fn test_thread_signal_swap() {
966972
thread::spawn(|| {
967973
let mut mask = SigSet::empty();
@@ -984,23 +990,14 @@ mod tests {
984990
}
985991

986992
#[test]
993+
#[cfg(not(target_os = "redox"))]
987994
fn test_sigaction() {
988995
use libc;
989996
thread::spawn(|| {
990997
extern fn test_sigaction_handler(_: libc::c_int) {}
991-
#[cfg(not(target_os = "redox"))]
992998
extern fn test_sigaction_action(_: libc::c_int,
993999
_: *mut libc::siginfo_t, _: *mut libc::c_void) {}
9941000

995-
#[cfg(not(target_os = "redox"))]
996-
fn test_sigaction_sigaction(flags: SaFlags, mask: SigSet) {
997-
let handler_act = SigHandler::SigAction(test_sigaction_action);
998-
let action_act = SigAction::new(handler_act, flags, mask);
999-
assert_eq!(action_act.handler(), handler_act);
1000-
}
1001-
#[cfg(target_os = "redox")]
1002-
fn test_sigaction_sigaction() {}
1003-
10041001
let handler_sig = SigHandler::Handler(test_sigaction_handler);
10051002

10061003
let flags = SaFlags::SA_ONSTACK | SaFlags::SA_RESTART |
@@ -1019,7 +1016,9 @@ mod tests {
10191016
assert!(mask.contains(SIGUSR1));
10201017
assert!(!mask.contains(SIGUSR2));
10211018

1022-
test_sigaction_sigaction(flags, mask);
1019+
let handler_act = SigHandler::SigAction(test_sigaction_action);
1020+
let action_act = SigAction::new(handler_act, flags, mask);
1021+
assert_eq!(action_act.handler(), handler_act);
10231022

10241023
let action_dfl = SigAction::new(SigHandler::SigDfl, flags, mask);
10251024
assert_eq!(action_dfl.handler(), SigHandler::SigDfl);
@@ -1030,6 +1029,7 @@ mod tests {
10301029
}
10311030

10321031
#[test]
1032+
#[cfg(not(target_os = "redox"))]
10331033
fn test_sigwait() {
10341034
thread::spawn(|| {
10351035
let mut mask = SigSet::empty();

src/sys/stat.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ pub fn utimensat<P: ?Sized + NixPath>(
289289
Errno::result(res).map(drop)
290290
}
291291

292+
#[cfg(not(target_os = "redox"))]
292293
pub fn mkdirat<P: ?Sized + NixPath>(fd: RawFd, path: &P, mode: Mode) -> Result<()> {
293294
let res = path.with_nix_path(|cstr| {
294295
unsafe { libc::mkdirat(fd, cstr.as_ptr(), mode.bits() as mode_t) }

src/unistd.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ pub fn setsid() -> Result<Pid> {
291291
/// Obtain the process group ID of the process that is the session leader of the process specified
292292
/// by pid. If pid is zero, it specifies the calling process.
293293
#[inline]
294+
#[cfg(not(target_os = "redox"))]
294295
pub fn getsid(pid: Option<Pid>) -> Result<Pid> {
295296
let res = unsafe { libc::getsid(pid.unwrap_or(Pid(0)).into()) };
296297
Errno::result(res).map(Pid)
@@ -1110,6 +1111,7 @@ fn pipe2_setflags(fd1: RawFd, fd2: RawFd, flags: OFlag) -> Result<()> {
11101111
///
11111112
/// See also
11121113
/// [truncate(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/truncate.html)
1114+
#[cfg(not(target_os = "redox"))]
11131115
pub fn truncate<P: ?Sized + NixPath>(path: &P, len: off_t) -> Result<()> {
11141116
let res = path.with_nix_path(|cstr| {
11151117
unsafe {
@@ -1513,6 +1515,7 @@ pub fn initgroups(user: &CStr, group: Gid) -> Result<()> {
15131515
///
15141516
/// See also [pause(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/pause.html).
15151517
#[inline]
1518+
#[cfg(not(target_os = "redox"))]
15161519
pub fn pause() {
15171520
unsafe { libc::pause() };
15181521
}

test/sys/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@ mod test_signal;
1313
mod test_aio;
1414
#[cfg(target_os = "linux")]
1515
mod test_signalfd;
16+
#[cfg(not(target_os = "redox"))]
1617
mod test_socket;
18+
#[cfg(not(target_os = "redox"))]
1719
mod test_sockopt;
20+
#[cfg(not(target_os = "redox"))]
1821
mod test_select;
1922
#[cfg(any(target_os = "android", target_os = "linux"))]
2023
mod test_sysinfo;
24+
#[cfg(not(target_os = "redox"))]
2125
mod test_termios;
26+
#[cfg(not(target_os = "redox"))]
2227
mod test_ioctl;
2328
mod test_wait;
2429
mod test_uio;

test/sys/test_pthread.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use nix::sys::pthread::*;
22

3-
#[cfg(target_env = "musl")]
3+
#[cfg(any(target_env = "musl", target_os = "redox"))]
44
#[test]
55
fn test_pthread_self() {
66
let tid = pthread_self();
77
assert!(tid != ::std::ptr::null_mut());
88
}
99

10-
#[cfg(not(target_env = "musl"))]
10+
#[cfg(not(any(target_env = "musl", target_os = "redox")))]
1111
#[test]
1212
fn test_pthread_self() {
1313
let tid = pthread_self();

test/sys/test_signal.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,16 @@ extern fn test_sigaction_handler(signal: libc::c_int) {
7979
SIGNALED.store(signal == Signal::SIGINT, Ordering::Relaxed);
8080
}
8181

82-
extern fn test_sigaction_action(_: libc::c_int, _: *mut libc::siginfo_t, _: *mut libc::c_void) {
82+
#[cfg(not(target_os = "redox"))]
83+
extern fn test_sigaction_action(_: libc::c_int, _: *mut libc::siginfo_t, _: *mut libc::c_void) {}
84+
85+
#[test]
86+
#[cfg(not(target_os = "redox"))]
87+
fn test_signal_sigaction() {
88+
let _m = ::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test");
89+
90+
let action_handler = SigHandler::SigAction(test_sigaction_action);
91+
assert_eq!(unsafe { signal(Signal::SIGINT, action_handler) }.unwrap_err(), Error::UnsupportedOperation);
8392
}
8493

8594
#[test]
@@ -96,9 +105,6 @@ fn test_signal() {
96105
assert!(SIGNALED.load(Ordering::Relaxed));
97106
assert_eq!(unsafe { signal(Signal::SIGINT, SigHandler::SigDfl) }.unwrap(), handler);
98107

99-
let action_handler = SigHandler::SigAction(test_sigaction_action);
100-
assert_eq!(unsafe { signal(Signal::SIGINT, action_handler) }.unwrap_err(), Error::UnsupportedOperation);
101-
102108
// Restore default signal handler
103109
unsafe { signal(Signal::SIGINT, SigHandler::SigDfl) }.unwrap();
104110
}

test/sys/test_wait.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use nix::sys::wait::*;
66
use libc::_exit;
77

88
#[test]
9+
#[cfg(not(target_os = "redox"))]
910
fn test_wait_signal() {
1011
let _ = ::FORK_MTX.lock().expect("Mutex got poisoned by another test");
1112

test/test.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ macro_rules! skip_if_not_root {
6262
}
6363

6464
mod sys;
65+
#[cfg(not(target_os = "redox"))]
6566
mod test_dir;
6667
mod test_fcntl;
6768
#[cfg(any(target_os = "android",
@@ -73,9 +74,12 @@ mod test_kmod;
7374
target_os = "linux",
7475
target_os = "netbsd"))]
7576
mod test_mq;
77+
#[cfg(not(target_os = "redox"))]
7678
mod test_net;
7779
mod test_nix_path;
80+
#[cfg(not(target_os = "redox"))]
7881
mod test_poll;
82+
#[cfg(not(target_os = "redox"))]
7983
mod test_pty;
8084
#[cfg(any(target_os = "android",
8185
target_os = "freebsd",

test/test_fcntl.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
use nix::fcntl::{openat, open, OFlag, readlink, readlinkat};
1+
use nix::fcntl::{open, OFlag, readlink};
2+
#[cfg(not(target_os = "redox"))]
3+
use nix::fcntl::{openat, readlinkat};
24
use nix::sys::stat::Mode;
35
use nix::unistd::{close, read};
46
use tempfile::{self, NamedTempFile};
57
use std::io::prelude::*;
68
use std::os::unix::fs;
79

810
#[test]
11+
#[cfg(not(target_os = "redox"))]
912
fn test_openat() {
1013
const CONTENTS: &[u8] = b"abcd";
1114
let mut tmp = NamedTempFile::new().unwrap();
@@ -28,6 +31,7 @@ fn test_openat() {
2831
}
2932

3033
#[test]
34+
#[cfg(not(target_os = "redox"))]
3135
fn test_readlink() {
3236
let tempdir = tempfile::tempdir().unwrap();
3337
let src = tempdir.path().join("a");

0 commit comments

Comments
 (0)