Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: zsh behavior when fork() failed
- X-seq: zsh-workers 30266
- From: Dipak Gaigole <dipakgaigole@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: zsh behavior when fork() failed
- Date: Fri, 24 Feb 2012 16:38:01 +0530
- Authentication-results: mr.google.com; spf=pass (google.com: domain of dipakgaigole@xxxxxxxxx designates 10.152.147.1 as permitted sender) smtp.mail=dipakgaigole@xxxxxxxxx; dkim=pass header.i=dipakgaigole@xxxxxxxxx
- Cc: zsh-workers@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=P+xkpoctkxkCcZ0FDaGi9e17zZEGgJST8tuQnkNaaUM=; b=ihI13mFEQ8Gkl1XCx3t/ZDESpa61Ar0cVnuBfL0afrs/Rwj2OLI03l6LzYwq89EbJq J2upAAMoxZjzGfBrvBkj/tRhz/A3puCGqP04ertkLHEir2C2aFvJKevY2tcmKCpM562H /LxuC5yKW044vntSxteE5jkgOls2Is7IjCzfs=
- In-reply-to: <120223081441.ZM2715@torch.brasslantern.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CADs2-=SFXA0rt1tKvBTnJC=UGdeaQk_GhSp_xM9EGFi_RW_YxA@mail.gmail.com> <120223081441.ZM2715@torch.brasslantern.com>
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