]>
Commit | Line | Data |
---|---|---|
416331ca | 1 | // run-pass |
92a42be0 SL |
2 | // Ignore this test on Android, because it segfaults there. |
3 | ||
4 | // ignore-android | |
5 | // ignore-windows | |
abe05a73 | 6 | // ignore-emscripten no execve |
48663c56 | 7 | // ignore-sgx no execve |
dfeec247 | 8 | // ignore-vxworks no execve |
f2b60f7d | 9 | // ignore-fuchsia no 'execve' |
92a42be0 SL |
10 | // no-prefer-dynamic |
11 | ||
0731742a | 12 | #![feature(rustc_private)] |
92a42be0 SL |
13 | |
14 | extern crate libc; | |
15 | ||
16 | use libc::c_char; | |
17 | use libc::execve; | |
18 | use std::env; | |
54a0048b SL |
19 | use std::ffi::CString; |
20 | use std::os::unix::prelude::*; | |
92a42be0 SL |
21 | use std::ptr; |
22 | ||
23 | fn main() { | |
24 | if env::args_os().count() == 2 { | |
25 | for (key, value) in env::vars_os() { | |
26 | panic!("found env value {:?} {:?}", key, value); | |
27 | } | |
28 | return; | |
29 | } | |
30 | ||
54a0048b SL |
31 | let current_exe = CString::new(env::current_exe() |
32 | .unwrap() | |
33 | .as_os_str() | |
34 | .as_bytes()).unwrap(); | |
35 | let new_env_var = CString::new("FOOBAR").unwrap(); | |
92a42be0 SL |
36 | let filename: *const c_char = current_exe.as_ptr(); |
37 | let argv: &[*const c_char] = &[filename, filename, ptr::null()]; | |
38 | let envp: &[*const c_char] = &[new_env_var.as_ptr(), ptr::null()]; | |
39 | unsafe { | |
40 | execve(filename, &argv[0], &envp[0]); | |
41 | } | |
42 | panic!("execve failed"); | |
43 | } |