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
1 change: 1 addition & 0 deletions src/uu/cat/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ cat-error-unknown-filetype = unknown filetype: { $ft_debug }
cat-error-is-directory = Is a directory
cat-error-input-file-is-output-file = input file is output file
cat-error-too-many-symbolic-links = Too many levels of symbolic links
cat-error-no-such-device-or-address = No such device or address
1 change: 1 addition & 0 deletions src/uu/cat/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ cat-error-unknown-filetype = type de fichier inconnu : { $ft_debug }
cat-error-is-directory = Est un répertoire
cat-error-input-file-is-output-file = le fichier d'entrée est le fichier de sortie
cat-error-too-many-symbolic-links = Trop de niveaux de liens symboliques
cat-error-no-such-device-or-address = Aucun appareil ou adresse de ce type
18 changes: 4 additions & 14 deletions src/uu/cat/src/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,10 @@ use memchr::memchr2;
use std::ffi::OsString;
use std::fs::{File, metadata};
use std::io::{self, BufWriter, ErrorKind, IsTerminal, Read, Write};
/// Unix domain socket support
#[cfg(unix)]
use std::net::Shutdown;
#[cfg(unix)]
use std::os::fd::AsFd;
#[cfg(unix)]
use std::os::unix::fs::FileTypeExt;
#[cfg(unix)]
use std::os::unix::net::UnixStream;
use thiserror::Error;
use uucore::display::Quotable;
use uucore::error::UResult;
Expand Down Expand Up @@ -103,6 +98,9 @@ enum CatError {
},
#[error("{}", translate!("cat-error-is-directory"))]
IsDirectory,
#[cfg(unix)]
#[error("{}", translate!("cat-error-no-such-device-or-address"))]
NoSuchDeviceOrAddress,
#[error("{}", translate!("cat-error-input-file-is-output-file"))]
OutputIsInput,
#[error("{}", translate!("cat-error-too-many-symbolic-links"))]
Expand Down Expand Up @@ -395,15 +393,7 @@ fn cat_path(path: &OsString, options: &OutputOptions, state: &mut OutputState) -
}
InputType::Directory => Err(CatError::IsDirectory),
#[cfg(unix)]
InputType::Socket => {
let socket = UnixStream::connect(path)?;
socket.shutdown(Shutdown::Write)?;
let mut handle = InputHandle {
reader: socket,
is_interactive: false,
};
cat_handle(&mut handle, options, state)
}
InputType::Socket => Err(CatError::NoSuchDeviceOrAddress),
_ => {
let file = File::open(path)?;
if is_unsafe_overwrite(&file, &io::stdout()) {
Expand Down
34 changes: 7 additions & 27 deletions tests/by-util/test_cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,37 +576,17 @@ fn test_write_fast_fallthrough_uses_flush() {

#[test]
#[cfg(unix)]
#[ignore = ""]
fn test_domain_socket() {
use std::io::prelude::*;
use std::os::unix::net::UnixListener;
use std::sync::{Arc, Barrier};
use std::thread;

let dir = tempfile::Builder::new()
.prefix("unix_socket")
.tempdir()
.expect("failed to create dir");
let socket_path = dir.path().join("sock");
let listener = UnixListener::bind(&socket_path).expect("failed to create socket");

// use a barrier to ensure we don't run cat before the listener is setup
let barrier = Arc::new(Barrier::new(2));
let barrier2 = Arc::clone(&barrier);

let thread = thread::spawn(move || {
let mut stream = listener.accept().expect("failed to accept connection").0;
barrier2.wait();
stream
.write_all(b"a\tb")
.expect("failed to write test data");
});

let child = new_ucmd!().args(&[socket_path]).run_no_wait();
barrier.wait();
child.wait().unwrap().stdout_is("a\tb");
let s = TestScenario::new(util_name!());
let socket_path = s.fixtures.plus("sock");
let _ = UnixListener::bind(&socket_path).expect("failed to create socket");

thread.join().unwrap();
s.ucmd()
.args(&[socket_path])
.fails()
.stderr_contains("No such device or address");
}

#[test]
Expand Down
Loading