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:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user