Skip to content

Commit

Permalink
fix/pty: check /proc/self/fd if /dev/fd does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
kxxt committed Oct 27, 2024
1 parent 12060dd commit 19830c8
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ pub fn close_random_fds() {
// a directory listing the current fd numbers for the process.
//
// On Linux, /dev/fd is a symlink to /proc/self/fd
if let Ok(dir) = std::fs::read_dir("/dev/fd") {
if let Ok(dir) = std::fs::read_dir("/proc/self/fd").or_else(|_| std::fs::read_dir("/dev/fd")) {
let mut fds = vec![];
for entry in dir {
if let Some(num) = entry
Expand All @@ -472,9 +472,7 @@ pub fn close_random_fds() {
}
}
for fd in fds {
unsafe {
libc::close(fd);
}
let _ = nix::unistd::close(fd);
}
}
}
Expand Down

0 comments on commit 19830c8

Please sign in to comment.