From 4e92198dbd4ede92216550c0facf12cd9dc890a3 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Mon, 18 Sep 2023 20:59:32 -0600 Subject: [PATCH] Fix the tty_path test on FreeBSD (#334) 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 https://github.com/bytecodealliance/rustix/pull/832 --- cap-primitives/src/rustix/fs/mod.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cap-primitives/src/rustix/fs/mod.rs b/cap-primitives/src/rustix/fs/mod.rs index a344d0b5..e69edc19 100644 --- a/cap-primitives/src/rustix/fs/mod.rs +++ b/cap-primitives/src/rustix/fs/mod.rs @@ -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"] };