summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLuca Bruno <lucab@debian.org>2017-11-19 09:13:53 +0000
committerLuca Bruno <lucab@debian.org>2017-11-19 20:33:23 +0000
commit8e463f52d41903a7253002aabe24e9447c0c14ed (patch)
tree71989b6b63220a4c7857bdddeea97a069430defa /test
parentcf3f236b908680ec0b55c527716c5860d0b3ce59 (diff)
downloadnix-8e463f52d41903a7253002aabe24e9447c0c14ed.zip
unistd: add execveat() on Linux and Android
This adds execveat() to `nix::unistd`. It uses the execveat(2) Linux kernel syscall, which is available since 3.19. This is a Linux-specific extension which is not covered by POSIX and does not have any userland libc wrapper. Ref: http://man7.org/linux/man-pages/man2/execveat.2.html
Diffstat (limited to 'test')
-rw-r--r--test/test_unistd.rs25
1 files changed, 23 insertions, 2 deletions
diff --git a/test/test_unistd.rs b/test/test_unistd.rs
index 672cbb9c..442c5921 100644
--- a/test/test_unistd.rs
+++ b/test/test_unistd.rs
@@ -1,5 +1,6 @@
extern crate tempdir;
+use nix::fcntl;
use nix::unistd::*;
use nix::unistd::ForkResult::*;
use nix::sys::wait::*;
@@ -190,7 +191,7 @@ fn test_initgroups() {
}
macro_rules! execve_test_factory(
- ($test_name:ident, $syscall:ident, $exe: expr) => (
+ ($test_name:ident, $syscall:ident, $exe: expr $(, $pathname:expr, $flags:expr)*) => (
#[test]
fn $test_name() {
#[allow(unused_variables)]
@@ -211,12 +212,14 @@ macro_rules! execve_test_factory(
// exec!
$syscall(
$exe,
+ $(&CString::new($pathname).unwrap(), )*
&[CString::new(b"".as_ref()).unwrap(),
CString::new(b"-c".as_ref()).unwrap(),
CString::new(b"echo nix!!! && echo foo=$foo && echo baz=$baz"
.as_ref()).unwrap()],
&[CString::new(b"foo=bar".as_ref()).unwrap(),
- CString::new(b"baz=quux".as_ref()).unwrap()]).unwrap();
+ CString::new(b"baz=quux".as_ref()).unwrap()]
+ $(, $flags)*).unwrap();
},
Parent { child } => {
// Wait for the child to exit.
@@ -252,6 +255,24 @@ cfg_if!{
}
}
+cfg_if!{
+ if #[cfg(target_os = "android")] {
+ execve_test_factory!(test_execveat_empty, execveat, File::open("/system/bin/sh").unwrap().into_raw_fd(),
+ "", fcntl::AT_EMPTY_PATH);
+ execve_test_factory!(test_execveat_relative, execveat, File::open("/system/bin/").unwrap().into_raw_fd(),
+ "./sh", fcntl::AtFlags::empty());
+ execve_test_factory!(test_execveat_absolute, execveat, File::open("/").unwrap().into_raw_fd(),
+ "/system/bin/sh", fcntl::AtFlags::empty());
+ } else if #[cfg(all(target_os = "linux"), any(target_arch ="x86_64", target_arch ="x86"))] {
+ execve_test_factory!(test_execveat_empty, execveat, File::open("/bin/sh").unwrap().into_raw_fd(),
+ "", fcntl::AT_EMPTY_PATH);
+ execve_test_factory!(test_execveat_relative, execveat, File::open("/bin/").unwrap().into_raw_fd(),
+ "./sh", fcntl::AtFlags::empty());
+ execve_test_factory!(test_execveat_absolute, execveat, File::open("/").unwrap().into_raw_fd(),
+ "/bin/sh", fcntl::AtFlags::empty());
+ }
+}
+
#[test]
fn test_fchdir() {
// fchdir changes the process's cwd