summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2019-10-07 14:25:45 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2019-10-07 14:25:45 +0200
commit427c12cc5199813328bf7fdf0bc4fc3a7672bf0f (patch)
tree2790a091588dc91d0ea1d83042f297e0739deafa
parent27f0e8a27584df50736398c26491c450b12fd00d (diff)
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>
-rw-r--r--coreutils/tee.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/coreutils/tee.c b/coreutils/tee.c
index fe5694331..e67296d43 100644
--- a/coreutils/tee.c
+++ b/coreutils/tee.c
@@ -39,6 +39,19 @@
//usage: "$ cat /tmp/foo\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 "common_bufsiz.h"
@@ -66,12 +79,12 @@ int tee_main(int argc, char **argv)
mode += (retval & 2); /* Since 'a' is the 2nd option... */
if (retval & 1) {
- signal(SIGINT, SIG_IGN); /* TODO - switch to sigaction. (why?) */
+ signal(SIGINT, SIG_IGN);
}
retval = EXIT_SUCCESS;
- /* gnu tee ignores SIGPIPE in case one of the output files is a pipe
- * that doesn't consume all its input. Good idea... */
- signal(SIGPIPE, SIG_IGN);
+ /* if (opt_p || opt_output_error)
+ signal(SIGPIPE, SIG_IGN);
+ */
/* Allocate an array of FILE *'s, with one extra for a sentinel. */
fp = files = xzalloc(sizeof(FILE *) * (argc + 2));
@@ -79,6 +92,7 @@ int tee_main(int argc, char **argv)
files[0] = stdout;
goto GOT_NEW_FILE;
+
do {
*fp = stdout;
if (NOT_LONE_DASH(*argv)) {
@@ -102,6 +116,7 @@ int tee_main(int argc, char **argv)
fp = files;
do
fwrite(buf, 1, c, *fp);
+ /* if (opt_p && fwrite() != c && !EPIPE) bb_error_msg("..."); */
while (*++fp);
}
if (c < 0) { /* Make sure read errors are signaled. */
@@ -113,6 +128,7 @@ int tee_main(int argc, char **argv)
fp = files;
do
putc(c, *fp);
+ /* if (opt_p && putc() == EOF && !EPIPE) bb_error_msg("..."); */
while (*++fp);
}
#endif