Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh behavior when fork() failed



On Thu, Feb 23, 2012 at 9:44 PM, Bart Schaefer
<schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> Perhaps you mean a case where script A calls script B, then script B
> fails but script A proceeds because the error wasn't propagated?

Yes, you are right. This is what I mean to say.

>
> Index: Src/exec.c
> ===================================================================
> --- Src/exec.c  20 Dec 2011 17:13:38 -0000      1.43
> +++ Src/exec.c  23 Feb 2012 16:07:50 -0000
> @@ -1617,9 +1617,8 @@
>                 (list_pipe || (pline_level && !(jn->stat & STAT_SUBJOB)))))
>                deletejob(jn, 0);
>            thisjob = pj;
> -
>        }
> -       if (slflags & WC_SUBLIST_NOT)
> +       if ((slflags & WC_SUBLIST_NOT) && !errflag)
>            lastval = !lastval;
>     }
>     if (!pline_level)
> @@ -2810,6 +2820,7 @@
>            close(synch[1]);
>            if (oautocont >= 0)
>                opts[AUTOCONTINUE] = oautocont;
> +           lastval = errflag = 1;
>            return;
>        }
>        if (pid) {
>

I have applied this patch and the newly built zsh returns proper $?
(i.e. 1) whenever fork fails. So this has fixed the behavior of error
propagation, but the script behavior still looks different.

Here is a simple script example:

bash-2.05b$ cat /tmp/test.sh
#!/bin/sh
x="My default value"
x=`date`
echo $?
echo "Current Date is:" "$x"
date
echo $?
bash-2.05b$


BASH:
bash-2.05b$ bash -x  /tmp/test.sh
+ x=My default value
/tmp/test.sh: fork: Resource temporarily unavailable
bash-2.05b$ echo $?
128
bash-2.05b$


KSH:
bash-2.05b$ ksh -x  /tmp/test.sh
+ x=My default value
/tmp/test.sh[3]: cannot fork - try again
bash-2.05b$ echo $?
1
bash-2.05b$


ZSH: (Applied above code patch)
bash-2.05b$ zsh -x  /tmp/test.sh
+/tmp/test.sh:2> x='My default value'
+/tmp/test.sh:3> x=/tmp/test.sh:3: fork failed: resource temporarily unavailable

+/tmp/test.sh:4> echo 1
1
+/tmp/test.sh:5> echo 'Current Date is:' 'My default value'
Current Date is: My default value
/tmp/test.sh:7: fork failed: resource temporarily unavailable
+/tmp/test.sh:8> echo 1
1
bash-2.05b$ echo $?
0
bash-2.05b$


As we can see that zsh continues even if it knows that it has failed
in fork and finally the script return status is 0.
Also checking for $? after each command is not feasible. So doesn't
this zsh behavior looks misleading?

Thanks,
Dipak



Messages sorted by: Reverse Date, Date, Thread, Author