diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2017-08-20 23:20:01 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2017-08-20 23:20:01 +0000 |
commit | 97caa0ca0d70f92119fcd9eb5d82b8acda637470 (patch) | |
tree | f97dfdf31f02be3406cd10d492f93d45c6993689 /test | |
parent | e2f9531aa0ac533bc9328943eb0aac883d10c625 (diff) | |
parent | d9f1b3df600b9e70c8a64baae9c8e39d2ce733a0 (diff) | |
download | nix-97caa0ca0d70f92119fcd9eb5d82b8acda637470.zip |
Merge #727
727: unistd: add fexecve() r=Susurrus
This adds fexecve(). It is available in libc since 0.2.29.
Ref: http://pubs.opengroup.org/onlinepubs/9699919799/functions/fexecve.html
Diffstat (limited to 'test')
-rw-r--r-- | test/test.rs | 2 | ||||
-rw-r--r-- | test/test_unistd.rs | 29 |
2 files changed, 21 insertions, 10 deletions
diff --git a/test/test.rs b/test/test.rs index 1d22b59a..1b73c4ff 100644 --- a/test/test.rs +++ b/test/test.rs @@ -1,4 +1,6 @@ #[macro_use] +extern crate cfg_if; +#[macro_use] extern crate nix; #[macro_use] extern crate lazy_static; diff --git a/test/test_unistd.rs b/test/test_unistd.rs index 09143c58..adf73579 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -105,7 +105,7 @@ mod linux_android { } macro_rules! execve_test_factory( - ($test_name:ident, $syscall:ident, $unix_sh:expr, $android_sh:expr) => ( + ($test_name:ident, $syscall:ident, $exe: expr) => ( #[test] fn $test_name() { #[allow(unused_variables)] @@ -119,19 +119,13 @@ macro_rules! execve_test_factory( // The tests make sure not to do that, though. match fork().unwrap() { Child => { - #[cfg(not(target_os = "android"))] - const SH_PATH: &'static [u8] = $unix_sh; - - #[cfg(target_os = "android")] - const SH_PATH: &'static [u8] = $android_sh; - // Close stdout. close(1).unwrap(); // Make `writer` be the stdout of the new process. dup(writer).unwrap(); // exec! $syscall( - &CString::new(SH_PATH).unwrap(), + $exe, &[CString::new(b"".as_ref()).unwrap(), CString::new(b"-c".as_ref()).unwrap(), CString::new(b"echo nix!!! && echo foo=$foo && echo baz=$baz" @@ -156,6 +150,23 @@ macro_rules! execve_test_factory( ) ); +cfg_if!{ + if #[cfg(target_os = "android")] { + execve_test_factory!(test_execve, execve, &CString::new("/system/bin/sh").unwrap()); + execve_test_factory!(test_fexecve, fexecve, File::open("/system/bin/sh").unwrap().into_raw_fd()); + } else if #[cfg(any(target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd", + target_os = "linux", ))] { + execve_test_factory!(test_execve, execve, &CString::new("/bin/sh").unwrap()); + execve_test_factory!(test_fexecve, fexecve, File::open("/bin/sh").unwrap().into_raw_fd()); + } else if #[cfg(any(target_os = "ios", target_os = "macos", ))] { + execve_test_factory!(test_execve, execve, &CString::new("/bin/sh").unwrap()); + // No fexecve() on macos/ios. + } +} + #[test] fn test_fchdir() { // fchdir changes the process's cwd @@ -231,8 +242,6 @@ fn test_lseek64() { close(tmpfd).unwrap(); } -execve_test_factory!(test_execve, execve, b"/bin/sh", b"/system/bin/sh"); - #[test] fn test_fpathconf_limited() { let f = tempfile().unwrap(); |