@@ -105,7 +105,7 @@ mod linux_android {
105
105
}
106
106
107
107
macro_rules! execve_test_factory(
108
- ( $test_name: ident, $syscall: ident, $unix_sh : expr , $android_sh : expr) => (
108
+ ( $test_name: ident, $syscall: ident, $exe : expr) => (
109
109
#[ test]
110
110
fn $test_name( ) {
111
111
#[ allow( unused_variables) ]
@@ -119,19 +119,13 @@ macro_rules! execve_test_factory(
119
119
// The tests make sure not to do that, though.
120
120
match fork( ) . unwrap( ) {
121
121
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
-
128
122
// Close stdout.
129
123
close( 1 ) . unwrap( ) ;
130
124
// Make `writer` be the stdout of the new process.
131
125
dup( writer) . unwrap( ) ;
132
126
// exec!
133
127
$syscall(
134
- & CString :: new ( SH_PATH ) . unwrap ( ) ,
128
+ $exe ,
135
129
& [ CString :: new( b"" . as_ref( ) ) . unwrap( ) ,
136
130
CString :: new( b"-c" . as_ref( ) ) . unwrap( ) ,
137
131
CString :: new( b"echo nix!!! && echo foo=$foo && echo baz=$baz"
@@ -156,6 +150,23 @@ macro_rules! execve_test_factory(
156
150
)
157
151
) ;
158
152
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
+
159
170
#[ test]
160
171
fn test_fchdir ( ) {
161
172
// fchdir changes the process's cwd
@@ -231,8 +242,6 @@ fn test_lseek64() {
231
242
close ( tmpfd) . unwrap ( ) ;
232
243
}
233
244
234
- execve_test_factory ! ( test_execve, execve, b"/bin/sh" , b"/system/bin/sh" ) ;
235
-
236
245
#[ test]
237
246
fn test_fpathconf_limited ( ) {
238
247
let f = tempfile ( ) . unwrap ( ) ;
0 commit comments