summary refs log tree commit diff
path: root/Src/jobs.c
diff options
context:
space:
mode:
authorPeter Stephenson <p.w.stephenson@ntlworld.com>2013-10-06 21:35:27 +0100
committerPeter Stephenson <p.w.stephenson@ntlworld.com>2013-10-06 21:35:27 +0100
commit52364258654418127d544d31b3c49b61019e2c7e (patch)
treec9942861227e2834769bea53a23f530703b8a8f0 /Src/jobs.c
parent16ff79a885f28bc9509901dd5d8ce9ccc9960811 (diff)
downloadzsh-52364258654418127d544d31b3c49b61019e2c7e.tar.gz
zsh-52364258654418127d544d31b3c49b61019e2c7e.tar.xz
zsh-52364258654418127d544d31b3c49b61019e2c7e.zip
users:18023: Add PIPEFAIL option
Diffstat (limited to 'Src/jobs.c')
-rw-r--r--Src/jobs.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/Src/jobs.c b/Src/jobs.c
index e1b24b2c9..b9d7a84cc 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -508,15 +508,22 @@ update_job(Job jn)
     jn->stat |= (somestopped) ? STAT_CHANGED | STAT_STOPPED :
 	STAT_CHANGED | STAT_DONE;
     if (job == thisjob && (jn->stat & STAT_DONE)) {
-	int i;
+	int i, newlastval = 0;
 	Process p;
 
-	for (p = jn->procs, i = 0; p && i < MAX_PIPESTATS; p = p->next, i++)
+	for (p = jn->procs, i = 0; p && i < MAX_PIPESTATS; p = p->next, i++) {
 	    pipestats[i] = ((WIFSIGNALED(p->status)) ?
 			    0200 | WTERMSIG(p->status) :
 			    WEXITSTATUS(p->status));
-	if ((jn->stat & STAT_CURSH) && i < MAX_PIPESTATS)
+	    if (pipestats[i])
+		newlastval = pipestats[i];
+	}
+	if ((jn->stat & STAT_CURSH) && i < MAX_PIPESTATS) {
 	    pipestats[i++] = lastval;
+	    if (!lastval && isset(PIPEFAIL))
+		lastval = newlastval;
+	} else if (isset(PIPEFAIL))
+	    lastval= newlastval;
 	numpipestats = i;
     }
     if (!inforeground &&