]> git.lizzy.rs Git - rust.git/blob - tests/ui/process/nofile-limit.rs
Rollup merge of #106446 - bzEq:fix-unwind-lsda, r=Amanieu
[rust.git] / tests / ui / process / nofile-limit.rs
1 // Check that statically linked binary executes successfully
2 // with RLIMIT_NOFILE resource lowered to zero. Regression
3 // test for issue #96621.
4 //
5 // run-pass
6 // dont-check-compiler-stderr
7 // only-linux
8 // no-prefer-dynamic
9 // compile-flags: -Ctarget-feature=+crt-static -Crpath=no -Crelocation-model=static
10 #![feature(exit_status_error)]
11 #![feature(rustc_private)]
12 extern crate libc;
13
14 use std::os::unix::process::CommandExt;
15 use std::process::Command;
16
17 fn main() {
18     let mut args = std::env::args();
19     let this = args.next().unwrap();
20     match args.next().as_deref() {
21         None => {
22             let mut cmd = Command::new(this);
23             cmd.arg("Ok!");
24             unsafe {
25                 cmd.pre_exec(|| {
26                     let rlim = libc::rlimit {
27                         rlim_cur: 0,
28                         rlim_max: 0,
29                     };
30                     if libc::setrlimit(libc::RLIMIT_NOFILE, &rlim) == -1 {
31                         Err(std::io::Error::last_os_error())
32                     } else {
33                         Ok(())
34                     }
35                 })
36             };
37             let output = cmd.output().unwrap();
38             println!("{:?}", output);
39             output.status.exit_ok().unwrap();
40             assert!(output.stdout.starts_with(b"Ok!"));
41         }
42         Some(word) => {
43             println!("{}", word);
44         }
45     }
46 }