From: Dipak Gaigole <dipakgaigole@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: zsh-workers@zsh.org
Subject: Re: zsh behavior when fork() failed
Date: Fri, 24 Feb 2012 16:38:01 +0530 [thread overview]
Message-ID: <CADs2-=Qz7RaX_ntVupWo=rk+-cKj45-i1K=rhm9p6Apw-xa5sQ@mail.gmail.com> (raw)
In-Reply-To: <120223081441.ZM2715@torch.brasslantern.com>
On Thu, Feb 23, 2012 at 9:44 PM, Bart Schaefer
<schaefer@brasslantern.com> 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
next prev parent reply other threads:[~2012-02-24 11:08 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-23 10:40 Dipak Gaigole
2012-02-23 16:14 ` Bart Schaefer
2012-02-24 11:08 ` Dipak Gaigole [this message]
2012-02-24 18:05 ` Bart Schaefer
2012-02-25 16:33 ` Dipak Gaigole
2012-02-26 19:52 ` Bart Schaefer
2012-02-26 21:57 ` Bart Schaefer
2012-02-29 12:57 ` Dipak Gaigole
2012-02-29 19:06 ` Bart Schaefer
2012-03-06 9:01 ` Dipak Gaigole
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CADs2-=Qz7RaX_ntVupWo=rk+-cKj45-i1K=rhm9p6Apw-xa5sQ@mail.gmail.com' \
--to=dipakgaigole@gmail.com \
--cc=schaefer@brasslantern.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).