]> git.lizzy.rs Git - rust.git/blob - tests/ui/command/command-uid-gid.rs
Rollup merge of #106644 - alexcrichton:update-wasi-toolchain, r=cuviper
[rust.git] / tests / ui / command / command-uid-gid.rs
1 // run-pass
2 // ignore-android
3 // ignore-emscripten
4 // ignore-sgx
5 // ignore-fuchsia no '/bin/sh', '/bin/ls'
6
7 #![feature(rustc_private)]
8
9 fn main() {
10     #[cfg(unix)]
11     run()
12 }
13
14 #[cfg(unix)]
15 fn run() {
16     extern crate libc;
17     use std::process::Command;
18     use std::os::unix::prelude::*;
19
20     let mut p = Command::new("/bin/sh")
21         .arg("-c").arg("true")
22         .uid(unsafe { libc::getuid() })
23         .gid(unsafe { libc::getgid() })
24         .spawn().unwrap();
25     assert!(p.wait().unwrap().success());
26
27     // if we're already root, this isn't a valid test. Most of the bots run
28     // as non-root though (android is an exception).
29     if unsafe { libc::getuid() != 0 } {
30         assert!(Command::new("/bin/ls").uid(0).gid(0).spawn().is_err());
31     }
32 }