about summary refs log tree commit diff
path: root/Src/exec.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2009-07-10 11:08:39 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2009-07-10 11:08:39 +0000
commit73be7ee553b1df74bfccb7742c79b620aec828ce (patch)
treee256c086d56b569273841eb3c93df2070958b1df /Src/exec.c
parentbd2ee44b78d4b1ef78eac9a897237d63aecc35d6 (diff)
downloadzsh-73be7ee553b1df74bfccb7742c79b620aec828ce.tar.gz
zsh-73be7ee553b1df74bfccb7742c79b620aec828ce.tar.xz
zsh-73be7ee553b1df74bfccb7742c79b620aec828ce.zip
27106: reset status on command that expands to empty
27122: add POSIX_JOBS option
Diffstat (limited to 'Src/exec.c')
-rw-r--r--Src/exec.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/Src/exec.c b/Src/exec.c
index 4f15ebefa..852d75bb5 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -151,6 +151,15 @@ pid_t cmdoutpid;
 /**/
 int cmdoutval;
 
+/*
+ * This is set by an exiting $(...) substitution to indicate we need
+ * to retain the status.  We initialize it to zero if we think we need
+ * to reset the status for a command.
+ */
+
+/**/
+int use_cmdoutval;
+
 /* The context in which a shell function is called, see SFC_* in zsh.h. */ 
 
 /**/
@@ -2262,6 +2271,14 @@ execcmd(Estate state, int input, int output, int how, int last1)
      */
     if (!args && varspc)
 	lastval = errflag ? errflag : cmdoutval;
+    /*
+     * If there are arguments, we should reset the status for the
+     * command before execution---unless we are using the result of a
+     * command substitution, which will be indicated by setting
+     * use_cmdoutval to 1.  We haven't kicked those off yet, so
+     * there's no race.
+     */
+    use_cmdoutval = !args;
 
     for (i = 0; i < 10; i++) {
 	save[i] = -2;
@@ -2478,7 +2495,12 @@ execcmd(Estate state, int input, int output, int how, int last1)
 		    lastval = 0;
 		    return;
 		} else {
-		    cmdoutval = lastval;
+		    /*
+		     * No arguments.  Reset the status if there were
+		     * arguments before and no command substitution
+		     * has provided a status.
+		     */
+		    cmdoutval = use_cmdoutval ? lastval : 0;
 		    if (varspc)
 			addvars(state, varspc, 0);
 		    if (errflag)
@@ -4674,6 +4696,7 @@ execsave(void)
     es->badcshglob = badcshglob;
     es->cmdoutpid = cmdoutpid;
     es->cmdoutval = cmdoutval;
+    es->use_cmdoutval = use_cmdoutval;
     es->trap_return = trap_return;
     es->trap_state = trap_state;
     es->trapisfunc = trapisfunc;
@@ -4704,6 +4727,7 @@ execrestore(void)
     badcshglob = exstack->badcshglob;
     cmdoutpid = exstack->cmdoutpid;
     cmdoutval = exstack->cmdoutval;
+    use_cmdoutval = exstack->use_cmdoutval;
     trap_return = exstack->trap_return;
     trap_state = exstack->trap_state;
     trapisfunc = exstack->trapisfunc;