]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/process-detach.rs
Imported Upstream version 1.1.0+dfsg1
[rustc.git] / src / test / run-pass / process-detach.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // ignore-test
12
13 // FIXME: this test is being ignored until signals are implemented
14
15 // This test ensures that the 'detach' field on processes does the right thing.
16 // By detaching the child process, they should be put into a separate process
17 // group. We test this by spawning a detached process, then killing our own
18 // group with a signal.
19 //
20 // Note that the first thing we do is put ourselves in our own process group so
21 // we don't interfere with other running tests.
22
23 extern crate libc;
24
25 use std::io::process;
26 use std::io::process::Command;
27 use std::io::signal::{Listener, Interrupt};
28
29 fn main() {
30 unsafe { libc::setsid(); }
31
32 // we shouldn't die because of an interrupt
33 let mut l = Listener::new();
34 l.register(Interrupt).unwrap();
35
36 // spawn the child
37 let mut p = Command::new("/bin/sh").arg("-c").arg("read a").detached().spawn().unwrap();
38
39 // send an interrupt to everyone in our process group
40 unsafe { libc::funcs::posix88::signal::kill(0, libc::SIGINT); }
41
42 // Wait for the child process to die (terminate it's stdin and the read
43 // should fail).
44 drop(p.stdin.take());
45 match p.wait().unwrap() {
46 process::ExitStatus(..) => {}
47 process::ExitSignal(..) => panic!()
48 }
49 }