aboutsummaryrefslogtreecommitdiff
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)
downloadbusybox-w32-427c12cc5199813328bf7fdf0bc4fc3a7672bf0f.tar.gz
busybox-w32-427c12cc5199813328bf7fdf0bc4fc3a7672bf0f.tar.bz2
busybox-w32-427c12cc5199813328bf7fdf0bc4fc3a7672bf0f.zip
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 @@
39//usage: "$ cat /tmp/foo\n" 39//usage: "$ cat /tmp/foo\n"
40//usage: "Hello\n" 40//usage: "Hello\n"
41 41
42// Bare "tee" with no below options does not install SIGPIPE handler - just dies on it.
43// TODO:
44// --output-error[=MODE]
45// 'warn' diagnose errors writing to any output
46// 'warn-nopipe' diagnose errors writing to any output not a pipe
47// 'exit' exit on error writing to any output
48// 'exit-nopipe' exit on error writing to any output not a pipe
49// ^^^ all of these should set SIGPIPE to SIG_IGN.
50// Because "exit" mode should print error message and exit1(1) - not die on SIGPIPE.
51// "exit-nopipe" does not exit on EPIPE and does not set exitcode to 1 too.
52// -p diagnose errors writing to non pipes
53// ^^^^ this should set SIGPIPE to SIG_IGN. EPIPE is ignored (same as "warn-nopipe")
54
42#include "libbb.h" 55#include "libbb.h"
43#include "common_bufsiz.h" 56#include "common_bufsiz.h"
44 57
@@ -66,12 +79,12 @@ int tee_main(int argc, char **argv)
66 mode += (retval & 2); /* Since 'a' is the 2nd option... */ 79 mode += (retval & 2); /* Since 'a' is the 2nd option... */
67 80
68 if (retval & 1) { 81 if (retval & 1) {
69 signal(SIGINT, SIG_IGN); /* TODO - switch to sigaction. (why?) */ 82 signal(SIGINT, SIG_IGN);
70 } 83 }
71 retval = EXIT_SUCCESS; 84 retval = EXIT_SUCCESS;
72 /* gnu tee ignores SIGPIPE in case one of the output files is a pipe 85 /* if (opt_p || opt_output_error)
73 * that doesn't consume all its input. Good idea... */ 86 signal(SIGPIPE, SIG_IGN);
74 signal(SIGPIPE, SIG_IGN); 87 */
75 88
76 /* Allocate an array of FILE *'s, with one extra for a sentinel. */ 89 /* Allocate an array of FILE *'s, with one extra for a sentinel. */
77 fp = files = xzalloc(sizeof(FILE *) * (argc + 2)); 90 fp = files = xzalloc(sizeof(FILE *) * (argc + 2));
@@ -79,6 +92,7 @@ int tee_main(int argc, char **argv)
79 92
80 files[0] = stdout; 93 files[0] = stdout;
81 goto GOT_NEW_FILE; 94 goto GOT_NEW_FILE;
95
82 do { 96 do {
83 *fp = stdout; 97 *fp = stdout;
84 if (NOT_LONE_DASH(*argv)) { 98 if (NOT_LONE_DASH(*argv)) {
@@ -102,6 +116,7 @@ int tee_main(int argc, char **argv)
102 fp = files; 116 fp = files;
103 do 117 do
104 fwrite(buf, 1, c, *fp); 118 fwrite(buf, 1, c, *fp);
119 /* if (opt_p && fwrite() != c && !EPIPE) bb_error_msg("..."); */
105 while (*++fp); 120 while (*++fp);
106 } 121 }
107 if (c < 0) { /* Make sure read errors are signaled. */ 122 if (c < 0) { /* Make sure read errors are signaled. */
@@ -113,6 +128,7 @@ int tee_main(int argc, char **argv)
113 fp = files; 128 fp = files;
114 do 129 do
115 putc(c, *fp); 130 putc(c, *fp);
131 /* if (opt_p && putc() == EOF && !EPIPE) bb_error_msg("..."); */
116 while (*++fp); 132 while (*++fp);
117 } 133 }
118#endif 134#endif