1 // Copyright 2015 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.
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.
23 use std::net::{TcpListener, TcpStream, UdpSocket};
24 use std::os::unix::prelude::*;
25 use std::process::{Command, Stdio};
29 let args = env::args().collect::<Vec<_>>();
38 let file = File::open(env::current_exe().unwrap()).unwrap();
39 let tcp1 = TcpListener::bind("127.0.0.1:0").unwrap();
40 let tcp2 = tcp1.try_clone().unwrap();
41 let addr = tcp1.local_addr().unwrap();
42 let t = thread::spawn(move || TcpStream::connect(addr).unwrap());
43 let tcp3 = tcp1.accept().unwrap().0;
44 let tcp4 = t.join().unwrap();
45 let tcp5 = tcp3.try_clone().unwrap();
46 let tcp6 = tcp4.try_clone().unwrap();
47 let udp1 = UdpSocket::bind("127.0.0.1:0").unwrap();
48 let udp2 = udp1.try_clone().unwrap();
50 let mut child = Command::new(env::args().next().unwrap())
52 .stdout(Stdio::piped())
53 .stdin(Stdio::piped())
54 .stderr(Stdio::piped())
56 let pipe1 = child.stdin.take().unwrap();
57 let pipe2 = child.stdout.take().unwrap();
58 let pipe3 = child.stderr.take().unwrap();
61 let status = Command::new(env::args().next().unwrap())
62 .arg(file.as_raw_fd().to_string())
63 .arg(tcp1.as_raw_fd().to_string())
64 .arg(tcp2.as_raw_fd().to_string())
65 .arg(tcp3.as_raw_fd().to_string())
66 .arg(tcp4.as_raw_fd().to_string())
67 .arg(tcp5.as_raw_fd().to_string())
68 .arg(tcp6.as_raw_fd().to_string())
69 .arg(udp1.as_raw_fd().to_string())
70 .arg(udp2.as_raw_fd().to_string())
71 .arg(pipe1.as_raw_fd().to_string())
72 .arg(pipe2.as_raw_fd().to_string())
73 .arg(pipe3.as_raw_fd().to_string())
76 assert!(status.success());
77 child.wait().unwrap();
80 fn child(args: &[String]) {
82 for arg in &args[1..] {
83 let fd: libc::c_int = arg.parse().unwrap();
85 assert_eq!(libc::read(fd, b.as_mut_ptr() as *mut _, 2), -1);
86 assert_eq!(io::Error::last_os_error().raw_os_error(),