4 // ignore-cloudabi no processes
5 // ignore-emscripten no processes
7 // ignore-sgx no processes
9 #![feature(rustc_private)]
16 use std::net::{TcpListener, TcpStream, UdpSocket};
17 use std::os::unix::prelude::*;
18 use std::process::{Command, Stdio};
22 let args = env::args().collect::<Vec<_>>();
31 let file = File::open(env::current_exe().unwrap()).unwrap();
32 let tcp1 = TcpListener::bind("127.0.0.1:0").unwrap();
33 let tcp2 = tcp1.try_clone().unwrap();
34 let addr = tcp1.local_addr().unwrap();
35 let t = thread::spawn(move || TcpStream::connect(addr).unwrap());
36 let tcp3 = tcp1.accept().unwrap().0;
37 let tcp4 = t.join().unwrap();
38 let tcp5 = tcp3.try_clone().unwrap();
39 let tcp6 = tcp4.try_clone().unwrap();
40 let udp1 = UdpSocket::bind("127.0.0.1:0").unwrap();
41 let udp2 = udp1.try_clone().unwrap();
43 let mut child = Command::new(env::args().next().unwrap())
45 .stdout(Stdio::piped())
46 .stdin(Stdio::piped())
47 .stderr(Stdio::piped())
49 let pipe1 = child.stdin.take().unwrap();
50 let pipe2 = child.stdout.take().unwrap();
51 let pipe3 = child.stderr.take().unwrap();
54 let status = Command::new(env::args().next().unwrap())
55 .arg(file.as_raw_fd().to_string())
56 .arg(tcp1.as_raw_fd().to_string())
57 .arg(tcp2.as_raw_fd().to_string())
58 .arg(tcp3.as_raw_fd().to_string())
59 .arg(tcp4.as_raw_fd().to_string())
60 .arg(tcp5.as_raw_fd().to_string())
61 .arg(tcp6.as_raw_fd().to_string())
62 .arg(udp1.as_raw_fd().to_string())
63 .arg(udp2.as_raw_fd().to_string())
64 .arg(pipe1.as_raw_fd().to_string())
65 .arg(pipe2.as_raw_fd().to_string())
66 .arg(pipe3.as_raw_fd().to_string())
69 assert!(status.success());
70 child.wait().unwrap();
73 fn child(args: &[String]) {
75 for arg in &args[1..] {
76 let fd: libc::c_int = arg.parse().unwrap();
78 assert_eq!(libc::read(fd, b.as_mut_ptr() as *mut _, 2), -1);
79 assert_eq!(io::Error::last_os_error().raw_os_error(),