From owner-freebsd-bugs Wed Feb 13 2:50: 8 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 4286F37B400 for ; Wed, 13 Feb 2002 02:50:02 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g1DAo1U79985; Wed, 13 Feb 2002 02:50:01 -0800 (PST) (envelope-from gnats) Date: Wed, 13 Feb 2002 02:50:01 -0800 (PST) Message-Id: <200202131050.g1DAo1U79985@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Bruce Evans Subject: Re: bin/34898: [PATCH] rev 1.7 of xargs.c broke documented exit status Reply-To: Bruce Evans Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org The following reply was made to PR bin/34898; it has been noted by GNATS. From: Bruce Evans To: Tim Robbins Cc: Subject: Re: bin/34898: [PATCH] rev 1.7 of xargs.c broke documented exit status Date: Wed, 13 Feb 2002 21:44:16 +1100 (EST) On Wed, 13 Feb 2002, Tim Robbins wrote: > >Description: > Revision 1.7 of src/usr.bin/xargs/xargs.c, which changed the vfork() call > to a fork(), broke the exit status 127 documented in xargs(1). > > It's broken in -STABLE and -CURRENT. execvp() now uses alloca(), so it might be safe for xargs to use vfork() again. > >Fix: > > Index: xargs/xargs.c > =================================================================== > RCS file: /home/ncvs/src/usr.bin/xargs/xargs.c,v > retrieving revision 1.11 > diff -u -r1.11 xargs.c > --- xargs/xargs.c 2001/12/11 22:36:26 1.11 > +++ xargs/xargs.c 2002/02/13 05:32:54 > @@ -296,7 +296,6 @@ > run(argv) > char **argv; > { > - volatile int noinvoke; > char **p; > pid_t pid; > int status; > @@ -308,21 +307,19 @@ > (void)fprintf(stderr, "\n"); > (void)fflush(stderr); > } > - noinvoke = 0; > switch(pid = fork()) { > case -1: > err(1, "fork"); > case 0: > execvp(argv[0], argv); > warn("%s", argv[0]); > - noinvoke = 1; > - _exit(1); > + _exit(254); > } > pid = waitpid(pid, &status, 0); > if (pid == -1) > err(1, "waitpid"); > /* If we couldn't invoke the utility, exit 127. */ > - if (noinvoke) > + if (WEXITSTATUS(status) == 254) > exit(127); > /* If utility signaled or exited with a value of 255, exit 1-125. */ > if (WIFSIGNALED(status) || WEXITSTATUS(status) == 255) The noinvoke hack has some advantages. Status 254 is a bit more fragile than it used to be. There is now a signal 126 and killing any process with this signal gives status 254. Bugs found while testing this: - /bin/kill doesn't support signals >= NSIG (32). - I use an old version of bash-1 for a shell. It dumps core when a process is killed by a signal >= 32. I think it was compiled when NSIG actually gave the number of signals. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message