Skip to content

Commit 35e63d0

Browse files
authored
Refactor file descriptor listing and command execution (#55)
1 parent 1ed805c commit 35e63d0

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

examples/spawn.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ use std::process::Command;
2121
use std::thread::sleep;
2222
use std::time::Duration;
2323

24-
/// Print out a list of all open file descriptors.
24+
/// Prints out a list of all open file descriptors.
2525
fn list_fds() {
2626
let dir = read_dir("/proc/self/fd").unwrap();
2727
for entry in dir {
2828
let entry = entry.unwrap();
2929
let target = read_link(entry.path()).unwrap();
30-
println!("{:?} {:?}", entry, target);
30+
println!("{:?} -> {:?}", entry.file_name(), target);
3131
}
3232
}
3333

@@ -41,8 +41,8 @@ fn main() {
4141

4242
// Prepare to run `ls -l /proc/self/fd` with some FDs mapped.
4343
let mut command = Command::new("ls");
44-
let stdin = stdin().as_fd().try_clone_to_owned().unwrap();
4544
command.arg("-l").arg("/proc/self/fd");
45+
let stdin_fd = stdin().as_fd().try_clone_to_owned().unwrap();
4646
command
4747
.fd_mappings(vec![
4848
// Map `file` as FD 3 in the child process.
@@ -52,13 +52,13 @@ fn main() {
5252
},
5353
// Map this process's stdin as FD 5 in the child process.
5454
FdMapping {
55-
parent_fd: stdin,
55+
parent_fd: stdin_fd,
5656
child_fd: 5,
5757
},
5858
])
5959
.unwrap();
6060
unsafe {
61-
command.pre_exec(move || {
61+
command.pre_exec(|| {
6262
println!("pre_exec");
6363
list_fds();
6464
Ok(())

0 commit comments

Comments
 (0)