Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: zsh behavior when fork() failed
- X-seq: zsh-workers 30301
- From: Dipak Gaigole <dipakgaigole@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: zsh behavior when fork() failed
- Date: Wed, 29 Feb 2012 18:27:22 +0530
- Authentication-results: mr.google.com; spf=pass (google.com: domain of dipakgaigole@xxxxxxxxx designates 10.112.103.8 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=7wXgn9jMWdqwJ3IjyZfrM7HFLX8ld15/ZNqpbbfP2SI=; b=uIhgNVt6i3PSMTMuygwsErues43nDhAp+WHoMOmd4tBaZCw3Q11I41EC+fLnbS0Jen jctG+lU+vvrSv+tBZHcBZfJ0fFTMRyEbkYeX2s5SOFe8mQndYqO0nN27p2HluPB8dEMJ hcRC6urr2HU9ZxUeAz2NH1ss0c60ECxsSspd4=
- In-reply-to: <120226115220.ZM17815@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> <CADs2-=Qz7RaX_ntVupWo=rk+-cKj45-i1K=rhm9p6Apw-xa5sQ@mail.gmail.com> <120224100518.ZM13322@torch.brasslantern.com> <CADs2-=RNMAHz=fQOWjVm25XRL4xaGLzTtA7yL-FCQPrHdV5jpg@mail.gmail.com> <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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author