Subject: bin/1240: problem with /bin/sh builtin `exit'
To: None <gnats-bugs@gnats.netbsd.org>
From: None <dennis@mci.net>
List: netbsd-bugs
Date: 07/18/1995 10:30:04
>Number: 1240
>Category: bin
>Synopsis: /bin/sh `exit' returns wrong status with no argument
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: bin-bug-people (Utility Bug People)
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Jul 18 10:35:00 1995
>Last-Modified:
>Originator: Dennis Ferguson
>Organization:
MCI
>Release: NetBSD 1.0A (-current of July 8)
>Environment:
Sun SS-II
System: NetBSD romford.reston.mci.net 1.0A NetBSD 1.0A (ROMFORD) #0: Sun Jul 9 10:58:27 PDT 1995 dennis@romford.reston.mci.net:/usr/src/sys/arch/sparc/compile/ROMFORD sparc
>Description:
The sh(1) manual page says the following about exit:
exit [ exitstatus ]
Terminate the shell process. If exitstatus is
given it is used as the exit status of the shell;
otherwise the exit status of the preceding command
is used.
The exit status returned by `exit' with no argument does not
match this description, but rather appears to be an unconditional
`0'. This may seem like an obscure problem, but is actually
fairly serious in practice since the ./configure scripts for many
packages depend on the manual page behaviour for correct results.
>How-To-Repeat:
romford% /bin/sh
$ (false ; exit) ; echo $?
0 -- should be 1
$ ((exit 222) ; exit) ; echo $?
0 -- should be 222
$
>Fix:
I think applying this to /usr/src/bin/sh/main.c will fix it.
*** main.c 1995/07/15 22:58:55 1.1
--- main.c 1995/07/15 23:09:34
***************
*** 341,350 ****
--- 341,354 ----
int argc;
char **argv;
{
+ extern int oexitstatus;
+
if (stoppedjobs())
return 0;
if (argc > 1)
exitstatus = number(argv[1]);
+ else
+ exitstatus = oexitstatus;
exitshell(exitstatus);
/*NOTREACHED*/
return 0;
>Audit-Trail:
>Unformatted: