Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh behavior when fork() failed



> 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



Messages sorted by: Reverse Date, Date, Thread, Author