]> git.proxmox.com Git - rustc.git/blame - src/test/ui/command-uid-gid.rs
New upstream version 1.40.0+dfsg1
[rustc.git] / src / test / ui / command-uid-gid.rs
CommitLineData
416331ca
XL
1// run-pass
2// ignore-android
3// ignore-cloudabi
4// ignore-emscripten
5// ignore-sgx
6
7#![feature(rustc_private)]
8
9fn main() {
10 #[cfg(unix)]
11 run()
12}
13
14#[cfg(unix)]
15fn 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}