Subject: bin/4378: xargs prints somewhat cryptic message on sigpipe
To: None <gnats-bugs@gnats.netbsd.org>
From: None <cgd@NetBSD.ORG>
List: netbsd-bugs
Date: 10/29/1997 02:02:32
>Number:         4378
>Category:       bin
>Synopsis:       xargs prints somewhat cryptic message on sigpipe
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Tue Oct 28 18:05:03 1997
>Last-Modified:
>Originator:     Chris G. Demetriou
>Organization:
Kernel Hackers 'r' Us
>Release:        NetBSD-current as of October 28, 1997
>Environment:
System: NetBSD brick.demetriou.com 1.3_ALPHA NetBSD 1.3_ALPHA (BRICK) #8: Mon Oct 27 22:40:17 PST 1997 cgd@brick.demetriou.com:/usr/src/sys/arch/i386/compile/BRICK i386


>Description:
	xargs prints a somwhat cryptic error message when its child
	dies with SIGPIPE.  I say "somewhat cryptic" because it made
	me go run a grep to see exactly what it was saying.

	In particular, it prints a message for the form:

		xargs: <progname> terminated by signal <signal>

	which turns out to be:

		xargs: strings terminated by signal 13

	for SIGPIPE if you're running 'strings'.

	Not everybody knows what signal 13 is (I didn't!), so
	this message can be confusing.  My first thought was "oooh,
	something's got a bug, let's find the core dump," and, of
	course, there was no core dump and I scratched my head for
	a few seconds.

	A better message would be something like:

		xargs: strings terminated by SIGPIPE

	or something similar.  Perhaps even better would be to print
	no message at all if the child terminates with SIGPIPE.
	sh and csh seem to take that approach.
	
>How-To-Repeat:
	find /bin /sbin -type f | xargs strings -a | grep -C -i copyright | more

	then "q" immediately.  Or, if you're prone to typos (as I am), try

	find /bin /sbin -type f | xargs strings -a | grep -C -i copyright more

	(note the missing | before more 8-).

	Note that you get a message:

	xargs: strings terminated by signal 13

>Fix:
	Enclosed are diffs that do both of the above: pretty-print signal
	names, and print nothing if the signal was SIGPIPE.  Pick whatever
	parts are useful.

Index: xargs.c
===================================================================
RCS file: /cvsroot/src/usr.bin/xargs/xargs.c,v
retrieving revision 1.9
diff -c -r1.9 xargs.c
*** xargs.c	1997/10/20 03:30:16	1.9
--- xargs.c	1997/10/29 01:59:45
***************
*** 58,63 ****
--- 58,64 ----
  #include <unistd.h>
  #include <limits.h>
  #include <locale.h>
+ #include <signal.h>
  #include <err.h>
  #include "pathnames.h"
  
***************
*** 319,325 ****
  			rval = 123;
  		}
  	} else if (WIFSIGNALED (status)) {
! 		warnx ("%s terminated by signal %d", argv[0], WTERMSIG(status));
  		exit(125);
  	}
  }
--- 320,333 ----
  			rval = 123;
  		}
  	} else if (WIFSIGNALED (status)) {
! 		if (WTERMSIG(status) != SIGPIPE) {
! 			if (WTERMSIG(status) < NSIG)
! 				warnx ("%s terminated by SIG%s", argv[0],
! 				    sys_signame[WTERMSIG(status)]);
! 			else
! 				warnx ("%s terminated by signal %d", argv[0],
! 				    WTERMSIG(status));
! 		}
  		exit(125);
  	}
  }
>Audit-Trail:
>Unformatted: