Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .vscode/cspell.dictionaries/workspace.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ IFSOCK
IRGRP
IROTH
IRUSR
ISDIR
ISGID
ISUID
ISVTX
Expand Down Expand Up @@ -205,6 +206,7 @@ setgid
setgroups
settime
setuid
socketpair
socktype
statfs
statp
Expand Down
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,13 @@ hex-literal = "1.0.0"
rstest.workspace = true

[target.'cfg(unix)'.dev-dependencies]
nix = { workspace = true, features = ["process", "signal", "user", "term"] }
nix = { workspace = true, features = [
"process",
"signal",
"socket",
"user",
"term",
] }
rlimit = "0.10.1"
xattr.workspace = true

Expand Down
4 changes: 3 additions & 1 deletion src/uucore/src/lib/features/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,9 @@ pub fn is_stdin_directory(stdin: &Stdin) -> bool {
{
use nix::sys::stat::fstat;
let mode = fstat(stdin.as_fd()).unwrap().st_mode as mode_t;
has!(mode, S_IFDIR)
// We use the S_IFMT mask ala S_ISDIR() to avoid mistaking
// sockets for directories.
mode & S_IFMT == S_IFDIR
}

#[cfg(windows)]
Expand Down
21 changes: 21 additions & 0 deletions tests/by-util/test_tr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1563,3 +1563,24 @@ fn test_broken_pipe_no_error() {
.run_stdout_starts_with(b"")
.fails_silently();
}

#[cfg(not(windows))]
#[test]
fn test_stdin_is_socket() {
use nix::sys::socket::{AddressFamily, SockFlag, SockType, socketpair};
use nix::unistd::write;

let (fd1, fd2) = socketpair(
AddressFamily::Unix,
SockType::Stream,
None,
SockFlag::empty(),
)
.unwrap();
write(fd1, b"::").unwrap();
new_ucmd!()
.args(&[":", ";"])
.set_stdin(fd2)
.succeeds()
.stdout_is(";;");
}
Loading