Subject: bin/2504: bin/sh: return returns wrong status
To: None <zuhause!!>
From: Bruce Albrecht <kksys!zuhause!>
List: netbsd-bugs
Date: 06/02/1996 21:06:14
>Number:         2504
>Category:       bin
>Synopsis:       bin/sh: return returns wrong status
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jun  3 00:20:02 1996
>Originator:     Bruce Albrecht
>Release:        1.2_ALPHA
	NetBSD 1.2_ALPHA, amiga A3000 68030.
System: NetBSD zuhause 1.2_ALPHA NetBSD 1.2_ALPHA (ZuHause) #0: Sat Jun 1 17:30:48 CDT 1996 bruce@zuhause:/NetBSD-current/netbsd/src/sys/arch/amiga/compile/ZuHause amiga

If a function exits with a return command with no parameters, it's suppose to
exit with the error code of the previous command.  In NetBSD 1.1 and 1.2_ALPHA
it returns 0.
Execute the following file:
t1() {
 echo "in t1"
 return 29
t2() {
 echo "in t2"
echo "in main"
echo "returned $?"

When I run this, I get:
sh ~bruce/treturn
in main
in t2
in t1
returned 0

Instead of 29.  This breaks the hylafax-4.0beta13 installation because it's 
full of *return* with no arguments.
To tell the truth, I haven't looked at this closely enough to understand why
exitstatus has been reset before eval calls returncmd, and setting a watch on 
exitstatus in gdb causes my machine to lock up.  This appears to work, though.

*** eval.c.bak  Sun Jun  2 19:50:14 1996
--- eval.c      Sun Jun  2 18:58:40 1996
*** 951,957 ****
        int ret;
!       ret = exitstatus;
        if (argc > 1)
                ret = number(argv[1]);
        if (funcnest) {
--- 951,957 ----
        int ret;
!       ret = oexitstatus;
        if (argc > 1)
                ret = number(argv[1]);
        if (funcnest) {