@@ -105,7 +105,7 @@ mod linux_android {
105105}
106106
107107macro_rules! execve_test_factory(
108- ( $test_name: ident, $syscall: ident, $unix_sh : expr , $android_sh : expr) => (
108+ ( $test_name: ident, $syscall: ident, $exe : expr) => (
109109 #[ test]
110110 fn $test_name( ) {
111111 #[ allow( unused_variables) ]
@@ -119,19 +119,13 @@ macro_rules! execve_test_factory(
119119 // The tests make sure not to do that, though.
120120 match fork( ) . unwrap( ) {
121121 Child => {
122- #[ cfg( not( target_os = "android" ) ) ]
123- const SH_PATH : & ' static [ u8 ] = $unix_sh;
124-
125- #[ cfg( target_os = "android" ) ]
126- const SH_PATH : & ' static [ u8 ] = $android_sh;
127-
128122 // Close stdout.
129123 close( 1 ) . unwrap( ) ;
130124 // Make `writer` be the stdout of the new process.
131125 dup( writer) . unwrap( ) ;
132126 // exec!
133127 $syscall(
134- & CString :: new ( SH_PATH ) . unwrap ( ) ,
128+ $exe ,
135129 & [ CString :: new( b"" . as_ref( ) ) . unwrap( ) ,
136130 CString :: new( b"-c" . as_ref( ) ) . unwrap( ) ,
137131 CString :: new( b"echo nix!!! && echo foo=$foo && echo baz=$baz"
@@ -156,6 +150,23 @@ macro_rules! execve_test_factory(
156150 )
157151) ;
158152
153+ cfg_if ! {
154+ if #[ cfg( target_os = "android" ) ] {
155+ execve_test_factory!( test_execve, execve, & CString :: new( "/system/bin/sh" ) . unwrap( ) ) ;
156+ execve_test_factory!( test_fexecve, fexecve, File :: open( "/system/bin/sh" ) . unwrap( ) . into_raw_fd( ) ) ;
157+ } else if #[ cfg( any( target_os = "dragonfly" ,
158+ target_os = "freebsd" ,
159+ target_os = "netbsd" ,
160+ target_os = "openbsd" ,
161+ target_os = "linux" , ) ) ] {
162+ execve_test_factory!( test_execve, execve, & CString :: new( "/bin/sh" ) . unwrap( ) ) ;
163+ execve_test_factory!( test_fexecve, fexecve, File :: open( "/bin/sh" ) . unwrap( ) . into_raw_fd( ) ) ;
164+ } else if #[ cfg( any( target_os = "ios" , target_os = "macos" , ) ) ] {
165+ execve_test_factory!( test_execve, execve, & CString :: new( "/bin/sh" ) . unwrap( ) ) ;
166+ // No fexecve() on macos/ios.
167+ }
168+ }
169+
159170#[ test]
160171fn test_fchdir ( ) {
161172 // fchdir changes the process's cwd
@@ -231,8 +242,6 @@ fn test_lseek64() {
231242 close ( tmpfd) . unwrap ( ) ;
232243}
233244
234- execve_test_factory ! ( test_execve, execve, b"/bin/sh" , b"/system/bin/sh" ) ;
235-
236245#[ test]
237246fn test_fpathconf_limited ( ) {
238247 let f = tempfile ( ) . unwrap ( ) ;
0 commit comments