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

Re: zsh behavior when fork() failed



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



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