6b4af4a
From c4ec43cec37ea82af6c0ba6bb0a3e8c3e85411ce Mon Sep 17 00:00:00 2001
2c4aecb
From: Pavel Raiskup <praiskup@redhat.com>
2c4aecb
Date: Mon, 28 Jul 2014 14:47:33 +0200
2c4aecb
Subject: [PATCH] downstream: implement variable tcsh_posix_status
2c4aecb
2c4aecb
  This patch partially reverts the dist-git commit e0b2d458fda4 -
2c4aecb
  because we *don't* really want to drop upstream-supported '$anyerror'
2c4aecb
  variable. And we can't drop $tcsh_posix_status neither, as we already
2c4aecb
  support that in RHEL5+ as a downstream patch.
2c4aecb
2c4aecb
  So from now, if "!defined(anyerror) ||  defined(tcsh_posix_status)",
2c4aecb
  tcsh behaves, with regards to pipelines, same way as POSIX-like shells.
2c4aecb
2c4aecb
  NOTE: This feature is left undocumented intentionaly, just to push
2c4aecb
        people use the upstream supported $anyerror.
2c4aecb
2c4aecb
  Resolves: #1129703
2c4aecb
  Related:  #759132
2c4aecb
---
2c4aecb
 sh.c               |  2 ++
2c4aecb
 sh.h               |  1 +
2c4aecb
 sh.proc.c          |  2 +-
2c4aecb
 sh.set.c           |  5 +++++
2c4aecb
 tc.const.c         |  2 ++
2c4aecb
 tests/variables.at | 28 ++++++++++++++++++++++++++++
2c4aecb
 6 files changed, 39 insertions(+), 1 deletion(-)
2c4aecb
2c4aecb
diff --git a/sh.c b/sh.c
6b4af4a
index e9dfa81..38d073a 100644
2c4aecb
--- a/sh.c
2c4aecb
+++ b/sh.c
2c4aecb
@@ -357,6 +357,8 @@ main(int argc, char **argv)
2c4aecb
     anyerror = 1;		/* for compatibility */
2c4aecb
     setcopy(STRanyerror, STRNULL, VAR_READWRITE);
2c4aecb
 
2c4aecb
+    tcsh_posix_status = 0;
2c4aecb
+
2c4aecb
     /* Default history size to 100 */
2c4aecb
     setcopy(STRhistory, str2short("100"), VAR_READWRITE);
2c4aecb
     sethistory(100);
2c4aecb
diff --git a/sh.h b/sh.h
6b4af4a
index 95f439d..a41e2e0 100644
2c4aecb
--- a/sh.h
2c4aecb
+++ b/sh.h
2c4aecb
@@ -573,6 +573,7 @@ EXTERN int    editing IZERO;	/* doing filename expansion and line editing */
2c4aecb
 EXTERN int    noediting IZERO;	/* initial $term defaulted to noedit */
2c4aecb
 EXTERN int    bslash_quote IZERO;/* PWP: tcsh-style quoting?  (in sh.c) */
2c4aecb
 EXTERN int    anyerror IZERO;	/* propagate errors from pipelines/backq */
2c4aecb
+EXTERN int    tcsh_posix_status	IZERO;	/* negation for anyerror */
2c4aecb
 EXTERN int    compat_expr IZERO;/* csh-style expressions? */
2c4aecb
 EXTERN int    isoutatty IZERO;	/* is SHOUT a tty */
2c4aecb
 EXTERN int    isdiagatty IZERO;/* is SHDIAG a tty */
2c4aecb
diff --git a/sh.proc.c b/sh.proc.c
6b4af4a
index 0af5e03..ac6ef5d 100644
2c4aecb
--- a/sh.proc.c
2c4aecb
+++ b/sh.proc.c
6b4af4a
@@ -564,7 +564,7 @@ pjwait(struct process *pp)
2c4aecb
     do {
2c4aecb
 	/* In case of pipelines only the result of the last
2c4aecb
 	 * command should be taken in account */
2c4aecb
-	if (!anyerror && !(fp->p_flags & PBRACE)
2c4aecb
+	if ((!anyerror || tcsh_posix_status) && !(fp->p_flags & PBRACE)
2c4aecb
 		&& ((fp->p_flags & PPOU) || (fp->p_flags & PBACKQ)))
2c4aecb
 	    continue;
2c4aecb
 	if (fp->p_reason)
2c4aecb
diff --git a/sh.set.c b/sh.set.c
6b4af4a
index cf831b2..c155619 100644
2c4aecb
--- a/sh.set.c
2c4aecb
+++ b/sh.set.c
2c4aecb
@@ -117,6 +117,9 @@ update_vars(Char *vp)
2c4aecb
     else if (eq(vp, STRanyerror)) {
2c4aecb
 	anyerror = 1;
2c4aecb
     }
2c4aecb
+    else if (eq(vp, STRtcsh_posix_status)) {
2c4aecb
+	tcsh_posix_status = 1;
2c4aecb
+    }
2c4aecb
     else if (eq(vp, STRsymlinks)) {
2c4aecb
 	Char *pn = varval(vp);
2c4aecb
 
2c4aecb
@@ -788,6 +791,8 @@ unset(Char **v, struct command *c)
2c4aecb
 	loginsh = 0;
2c4aecb
     if (adrof(STRanyerror) == 0)
2c4aecb
 	anyerror = 0;
2c4aecb
+    if (adrof(STRtcsh_posix_status) == 0)
2c4aecb
+	tcsh_posix_status = 0;
2c4aecb
     if (adrof(STRwordchars) == 0)
2c4aecb
 	word_chars = STR_WORD_CHARS;
2c4aecb
     if (adrof(STRedit) == 0)
2c4aecb
diff --git a/tc.const.c b/tc.const.c
6b4af4a
index cb39ab9..4fed182 100644
2c4aecb
--- a/tc.const.c
2c4aecb
+++ b/tc.const.c
2c4aecb
@@ -44,6 +44,8 @@ Char STRrootdefautologout[] = { '1', '5', '\0' };
2c4aecb
 Char STRautomatic[]	= { 'a', 'u', 't', 'o', 'm', 'a', 't', 'i', 'c',
2c4aecb
 			    '\0' };
2c4aecb
 Char STRanyerror[]	= { 'a', 'n', 'y', 'e', 'r', 'r', 'o', 'r', '\0' };
2c4aecb
+Char STRtcsh_posix_status[] = {'t', 'c', 's', 'h', '_', 'p', 'o', 's', 'i', 'x',
2c4aecb
+			       '_', 's', 't', 'a', 't', 'u', 's', '\0' };
2c4aecb
 Char STRhangup[]	= { 'h', 'a', 'n', 'g', 'u', 'p', '\0' };
2c4aecb
 Char STRaout[]		= { 'a', '.', 'o', 'u', 't', '\0' };
2c4aecb
 Char STRtty[]		= { 't', 't', 'y', '\0' };
2c4aecb
diff --git a/tests/variables.at b/tests/variables.at
6b4af4a
index ffa0da2..5fa9239 100644
2c4aecb
--- a/tests/variables.at
2c4aecb
+++ b/tests/variables.at
6b4af4a
@@ -976,6 +976,34 @@ AT_CHECK([tcsh -f -c 'echo $?tcsh'], ,
2c4aecb
 AT_CLEANUP
2c4aecb
 
2c4aecb
 
2c4aecb
+AT_SETUP([$ tcsh_posix_status])
2c4aecb
+
2c4aecb
+AT_DATA([exit_status.csh],
2c4aecb
+[[echo $?tcsh_posix_status
2c4aecb
+false | true ; echo $?
2c4aecb
+set tcsh_posix_status = 1 ; echo $?tcsh_posix_status $tcsh_posix_status
2c4aecb
+false | true ; echo $?
2c4aecb
+set tcsh_posix_status = 0 ; echo $?tcsh_posix_status $tcsh_posix_status
2c4aecb
+# Note it is still set!
2c4aecb
+false | true ; echo $?
2c4aecb
+unset tcsh_posix_status ; echo $?tcsh_posix_status
2c4aecb
+false | true ; echo $?
2c4aecb
+]])
2c4aecb
+
2c4aecb
+AT_CHECK([tcsh -f exit_status.csh],,
2c4aecb
+[0
2c4aecb
+1
2c4aecb
+1 1
2c4aecb
+0
2c4aecb
+1 0
2c4aecb
+0
2c4aecb
+0
2c4aecb
+1
2c4aecb
+])
2c4aecb
+
2c4aecb
+AT_CLEANUP
2c4aecb
+
2c4aecb
+
2c4aecb
 AT_SETUP([$ term])
2c4aecb
 
2c4aecb
 AT_DATA([term.csh],
2c4aecb
-- 
6b4af4a
2.7.4
2c4aecb