Skip to content

Commit

Permalink
Fix the tty_path test on FreeBSD (#334)
Browse files Browse the repository at this point in the history
On FreeBSD, ttyname(3) may not return exactly the same name as was used
to open the file descriptor.  For example, "/dev/tty" is an alias for
whatever the real tty device is.  But paths like "/dev/pts/0" aren't
aliases.  If the user can open them, ttyname() will always return their
own name.

Note that the test will still fail on non-Linux, non-Darwin due to an
unrelated Rustix bug.  See
bytecodealliance/rustix#832
  • Loading branch information
asomers authored Sep 19, 2023
1 parent 5e9248c commit 4e92198
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cap-primitives/src/rustix/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ fn tty_path() {
#[cfg(unix)]
use std::os::unix::fs::FileTypeExt;

// On FreeBSD, `ttyname` doesn't seem to work on /dev/std{in,out,err}.
// On FreeBSD, /dev/{tty,stdin,stdout,stderr} are aliases to different real
// devices.
let paths: &[&str] = if cfg!(target_os = "freebsd") {
&["/dev/tty"]
&["/dev/ttyv0", "/dev/pts/0"]
} else {
&["/dev/tty", "/dev/stdin", "/dev/stdout", "/dev/stderr"]
};
Expand Down

0 comments on commit 4e92198

Please sign in to comment.