From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5289 invoked by alias); 23 Feb 2012 16:15:33 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 30261 Received: (qmail 24215 invoked from network); 23 Feb 2012 16:15:16 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <120223081441.ZM2715@torch.brasslantern.com> Date: Thu, 23 Feb 2012 08:14:41 -0800 In-reply-to: Comments: In reply to Dipak Gaigole "zsh behavior when fork() failed" (Feb 23, 4:10pm) References: X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Dipak Gaigole , zsh-workers@zsh.org Subject: Re: zsh behavior when fork() failed MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Feb 23, 4:10pm, Dipak Gaigole wrote: } } [dipak@rhas30]/tmp% date } zsh: fork failed: resource temporarily unavailable } [dipak@rhas30]/tmp% echo $? } 0 There are several places where zsh forks without obviously propagating the error state, but I only found one case where $? was zero after the command. If the command is part of a pipeline, or is in $(...) or any process substitution, then $? is properly set to 1. However, there are other differences from bash. For example, in zsh, the "not" operator inverts the fork-failed error state: torch% date | read -E zsh: fork failed: resource temporarily unavailable torch% print $? 1 torch% ! date | read -E zsh: fork failed: resource temporarily unavailable torch% print $? 0 In bash, the result is 1 in both cases. The appended patch seems to fix both situations, but in some of the instances of fork failure I haven't traced through how lastval and errflag both get set (except it doesn't happen at the point of the fork) so it is possible that some form of command is still wrong. } As we can see that in zsh whenever fork() fails with EAGAIN, the } return status is incorrect (i.e. $? is 0) and this causes further } failures if this happens in a big script where script's progress } depends on execution of previous command i.e $? Can you provide an example script? A simple one that I put together bails out on fork failure even though $? is zero. 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? 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) {