zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Dipak Gaigole <dipakgaigole@gmail.com>, zsh-workers@zsh.org
Subject: Re: zsh behavior when fork() failed
Date: Thu, 23 Feb 2012 08:14:41 -0800	[thread overview]
Message-ID: <120223081441.ZM2715@torch.brasslantern.com> (raw)
In-Reply-To: <CADs2-=SFXA0rt1tKvBTnJC=UGdeaQk_GhSp_xM9EGFi_RW_YxA@mail.gmail.com>

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) {


  reply	other threads:[~2012-02-23 16:15 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 [this message]
2012-02-24 11:08   ` Dipak Gaigole
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=120223081441.ZM2715@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=dipakgaigole@gmail.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).