1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

Merge pull request #1658 from sylvestre/tee-ignore-interrupts

tee: implement ignore-interrupts option
This commit is contained in:
Sylvestre Ledru 2020-12-16 08:46:40 +01:00 committed by GitHub
commit 4e2bd86811
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,6 +12,7 @@ extern crate uucore;
use std::fs::OpenOptions;
use std::io::{copy, sink, stdin, stdout, Error, ErrorKind, Read, Result, Write};
use std::path::{Path, PathBuf};
use uucore::libc;
static NAME: &str = "tee";
static VERSION: &str = env!("CARGO_PKG_VERSION");
@ -38,7 +39,11 @@ fn options(args: &[String]) -> Result<Options> {
let mut opts = getopts::Options::new();
opts.optflag("a", "append", "append to the given FILEs, do not overwrite");
opts.optflag("i", "ignore-interrupts", "ignore interrupt signals");
opts.optflag(
"i",
"ignore-interrupts",
"ignore interrupt signals (ignored on non-Unix platforms)",
);
opts.optflag("h", "help", "display this help and exit");
opts.optflag("V", "version", "output version information and exit");
@ -86,7 +91,25 @@ fn exec(options: Options) -> Result<()> {
}
}
#[cfg(unix)]
fn ignore_interrupts() -> Result<()> {
let ret = unsafe { libc::signal(libc::SIGINT, libc::SIG_IGN) };
if ret == libc::SIG_ERR {
return Err(Error::new(ErrorKind::Other, ""));
}
Ok(())
}
#[cfg(not(unix))]
fn ignore_interrupts() -> Result<()> {
// Do nothing.
Ok(())
}
fn tee(options: Options) -> Result<()> {
if options.ignore_interrupts {
ignore_interrupts()?
}
let mut writers: Vec<Box<dyn Write>> = options
.files
.clone()