1
1
extern crate tempdir;
2
2
3
+ use nix:: fcntl;
3
4
use nix:: unistd:: * ;
4
5
use nix:: unistd:: ForkResult :: * ;
5
6
use nix:: sys:: wait:: * ;
@@ -190,7 +191,7 @@ fn test_initgroups() {
190
191
}
191
192
192
193
macro_rules! execve_test_factory(
193
- ( $test_name: ident, $syscall: ident, $exe: expr) => (
194
+ ( $test_name: ident, $syscall: ident, $exe: expr $ ( , $pathname : expr , $flags : expr ) * ) => (
194
195
#[ test]
195
196
fn $test_name( ) {
196
197
#[ allow( unused_variables) ]
@@ -211,12 +212,14 @@ macro_rules! execve_test_factory(
211
212
// exec!
212
213
$syscall(
213
214
$exe,
215
+ $( & CString :: new( $pathname) . unwrap( ) , ) *
214
216
& [ CString :: new( b"" . as_ref( ) ) . unwrap( ) ,
215
217
CString :: new( b"-c" . as_ref( ) ) . unwrap( ) ,
216
218
CString :: new( b"echo nix!!! && echo foo=$foo && echo baz=$baz"
217
219
. as_ref( ) ) . unwrap( ) ] ,
218
220
& [ CString :: new( b"foo=bar" . as_ref( ) ) . unwrap( ) ,
219
- CString :: new( b"baz=quux" . as_ref( ) ) . unwrap( ) ] ) . unwrap( ) ;
221
+ CString :: new( b"baz=quux" . as_ref( ) ) . unwrap( ) ]
222
+ $( , $flags) * ) . unwrap( ) ;
220
223
} ,
221
224
Parent { child } => {
222
225
// Wait for the child to exit.
@@ -252,6 +255,24 @@ cfg_if!{
252
255
}
253
256
}
254
257
258
+ cfg_if ! {
259
+ if #[ cfg( target_os = "android" ) ] {
260
+ execve_test_factory!( test_execveat_empty, execveat, File :: open( "/system/bin/sh" ) . unwrap( ) . into_raw_fd( ) ,
261
+ "" , fcntl:: AT_EMPTY_PATH ) ;
262
+ execve_test_factory!( test_execveat_relative, execveat, File :: open( "/system/bin/" ) . unwrap( ) . into_raw_fd( ) ,
263
+ "./sh" , fcntl:: AtFlags :: empty( ) ) ;
264
+ execve_test_factory!( test_execveat_absolute, execveat, File :: open( "/" ) . unwrap( ) . into_raw_fd( ) ,
265
+ "/system/bin/sh" , fcntl:: AtFlags :: empty( ) ) ;
266
+ } else if #[ cfg( all( target_os = "linux" ) , any( target_arch ="x86_64" , target_arch ="x86" ) ) ] {
267
+ execve_test_factory!( test_execveat_empty, execveat, File :: open( "/bin/sh" ) . unwrap( ) . into_raw_fd( ) ,
268
+ "" , fcntl:: AT_EMPTY_PATH ) ;
269
+ execve_test_factory!( test_execveat_relative, execveat, File :: open( "/bin/" ) . unwrap( ) . into_raw_fd( ) ,
270
+ "./sh" , fcntl:: AtFlags :: empty( ) ) ;
271
+ execve_test_factory!( test_execveat_absolute, execveat, File :: open( "/" ) . unwrap( ) . into_raw_fd( ) ,
272
+ "/bin/sh" , fcntl:: AtFlags :: empty( ) ) ;
273
+ }
274
+ }
275
+
255
276
#[ test]
256
277
fn test_fchdir ( ) {
257
278
// fchdir changes the process's cwd
0 commit comments