//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"
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));
files[0] = stdout;
goto GOT_NEW_FILE;
+
do {
*fp = stdout;
if (NOT_LONE_DASH(*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. */
fp = files;
do
putc(c, *fp);
+ /* if (opt_p && putc() == EOF && !EPIPE) bb_error_msg("..."); */
while (*++fp);
}
#endif