tee: do not intercept SIGPIPE

GNU tee does this only with -p, which we don't have yet.

function                                             old     new   delta
tee_main                                             306     295     -11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2019-10-07 14:25:45 +02:00
parent 27f0e8a275
commit 427c12cc51

View File

@ -39,6 +39,19 @@
//usage: "$ cat /tmp/foo\n" //usage: "$ cat /tmp/foo\n"
//usage: "Hello\n" //usage: "Hello\n"
// Bare "tee" with no below options does not install SIGPIPE handler - just dies on it.
// TODO:
// --output-error[=MODE]
// 'warn' diagnose errors writing to any output
// 'warn-nopipe' diagnose errors writing to any output not a pipe
// 'exit' exit on error writing to any output
// 'exit-nopipe' exit on error writing to any output not a pipe
// ^^^ all of these should set SIGPIPE to SIG_IGN.
// Because "exit" mode should print error message and exit1(1) - not die on SIGPIPE.
// "exit-nopipe" does not exit on EPIPE and does not set exitcode to 1 too.
// -p diagnose errors writing to non pipes
// ^^^^ this should set SIGPIPE to SIG_IGN. EPIPE is ignored (same as "warn-nopipe")
#include "libbb.h" #include "libbb.h"
#include "common_bufsiz.h" #include "common_bufsiz.h"
@ -66,12 +79,12 @@ int tee_main(int argc, char **argv)
mode += (retval & 2); /* Since 'a' is the 2nd option... */ mode += (retval & 2); /* Since 'a' is the 2nd option... */
if (retval & 1) { if (retval & 1) {
signal(SIGINT, SIG_IGN); /* TODO - switch to sigaction. (why?) */ signal(SIGINT, SIG_IGN);
} }
retval = EXIT_SUCCESS; retval = EXIT_SUCCESS;
/* gnu tee ignores SIGPIPE in case one of the output files is a pipe /* if (opt_p || opt_output_error)
* that doesn't consume all its input. Good idea... */
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
*/
/* Allocate an array of FILE *'s, with one extra for a sentinel. */ /* Allocate an array of FILE *'s, with one extra for a sentinel. */
fp = files = xzalloc(sizeof(FILE *) * (argc + 2)); fp = files = xzalloc(sizeof(FILE *) * (argc + 2));
@ -79,6 +92,7 @@ int tee_main(int argc, char **argv)
files[0] = stdout; files[0] = stdout;
goto GOT_NEW_FILE; goto GOT_NEW_FILE;
do { do {
*fp = stdout; *fp = stdout;
if (NOT_LONE_DASH(*argv)) { if (NOT_LONE_DASH(*argv)) {
@ -102,6 +116,7 @@ int tee_main(int argc, char **argv)
fp = files; fp = files;
do do
fwrite(buf, 1, c, *fp); fwrite(buf, 1, c, *fp);
/* if (opt_p && fwrite() != c && !EPIPE) bb_error_msg("..."); */
while (*++fp); while (*++fp);
} }
if (c < 0) { /* Make sure read errors are signaled. */ if (c < 0) { /* Make sure read errors are signaled. */
@ -113,6 +128,7 @@ int tee_main(int argc, char **argv)
fp = files; fp = files;
do do
putc(c, *fp); putc(c, *fp);
/* if (opt_p && putc() == EOF && !EPIPE) bb_error_msg("..."); */
while (*++fp); while (*++fp);
} }
#endif #endif