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: Wed, 29 Feb 2012 18:27:22 +0530 [thread overview]
Message-ID: <CADs2-=Qb4o9gh_40ASr8HNGfpSz8XLEcy0pqQLnJC+eE6ZvRSg@mail.gmail.com> (raw)
In-Reply-To: <120226115220.ZM17815@torch.brasslantern.com>
> There are a couple of other cases (e.g., around line 1680) where's also
> possible the error should be considered unrecoverable.
>
> That would make a full patch look something like the following (which
> still exits with 1, rather than with 128 like bash, but does exit).
> The oautocont stuff goes away because it's handled below the "fatal"
> label (outside the visible diff context). The second hunk still might
> not cause a proper exit, it's in execpline2() from which it's less clear
> to me how to reach the "fatal" condition but it's pretty obvious that
> it shouldn't just be falling through in those error states.
>
>
> Index: Src/exec.c
> --- ../zsh-forge/current/Src/exec.c 2012-02-12 13:31:49.000000000 -0800
> +++ Src/exec.c 2012-02-26 11:47:48.000000000 -0800
> @@ -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)
> @@ -1679,9 +1678,13 @@
>
> if (pipe(synch) < 0) {
> zerr("pipe failed: %e", errno);
> + lastval = errflag = 1;
> + return;
> } else if ((pid = zfork(&bgtime)) == -1) {
> close(synch[0]);
> close(synch[1]);
> + lastval = errflag = 1;
> + return;
> } else if (pid) {
> char dummy, *text;
>
> @@ -2490,7 +2493,7 @@
> if (!firstnode(args)) {
> zerr("exec requires a command to execute");
> errflag = lastval = 1;
> - return;
> + goto fatal;
> }
> uremnode(args, firstnode(args));
> if (!strcmp(next, "--"))
> @@ -2507,12 +2510,12 @@
> if (!firstnode(args)) {
> zerr("exec requires a command to execute");
> errflag = lastval = 1;
> - return;
> + goto fatal;
> }
> if (!nextnode(firstnode(args))) {
> zerr("exec flag -a requires a parameter");
> errflag = lastval = 1;
> - return;
> + goto fatal;
> }
> exec_argv0 = (char *)
> getdata(nextnode(firstnode(args)));
> @@ -2813,15 +2816,12 @@
>
> if (pipe(synch) < 0) {
> zerr("pipe failed: %e", errno);
> - if (oautocont >= 0)
> - opts[AUTOCONTINUE] = oautocont;
> - return;
> + goto fatal;
> } else if ((pid = zfork(&bgtime)) == -1) {
> close(synch[0]);
> close(synch[1]);
> - if (oautocont >= 0)
> - opts[AUTOCONTINUE] = oautocont;
> - return;
> + lastval = errflag = 1;
> + goto fatal;
> }
> if (pid) {
>
> @@ -3365,6 +3365,7 @@
> * classify as a builtin) we treat all errors as fatal.
> * The "command" builtin is not special so resets this behaviour.
> */
> + fatal:
> if (redir_err || errflag) {
> if (!isset(INTERACTIVE)) {
> if (forked)
I have applied this patch but unfortunately the script still continues
even after the fork failures while executing commands from the script.
bash-2.05b$ cat /tmp/test1.sh
#!/bin/sh
x="My default value"
x=`date`
echo $?
echo "Current Date is:" "$x"
date
echo $?
bash-2.05b$ zsh /tmp/test1.sh
/tmp/test1.sh:3: fork failed: resource temporarily unavailable
1
Current Date is: My default value
/tmp/test1.sh:6: fork failed: resource temporarily unavailable
1
bash-2.05b$
Can you please check this on your end?
Thanks,
Dipak
next prev parent reply other threads:[~2012-02-29 13:26 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
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 [this message]
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-=Qb4o9gh_40ASr8HNGfpSz8XLEcy0pqQLnJC+eE6ZvRSg@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).