804e626
From 5f012d155159b96f2a458ba047085cb1b348befc Mon Sep 17 00:00:00 2001
804e626
From: Pavel Raiskup <praiskup@redhat.com>
804e626
Date: Mon, 28 Jul 2014 14:47:33 +0200
804e626
Subject: [PATCH 13/15] downstream: implement variable tcsh_posix_status
804e626
804e626
This patch partially reverts the dist-git commit e0b2d458fda4
804e626
because we _don't_ really want drop upstream-supported 'anyerror'
804e626
variable.  And we can not drop tcsh_posix_status neither, as we
804e626
already support that in RHEL5+ downstream.
804e626
804e626
So from now, if "!defined(anyerror) ||
804e626
defined(tcsh_posix_status)", tcsh behaves, with regards to
804e626
pipelines, same way as POSIX-like shells.
804e626
804e626
Note: This feature is left undocumented intentionaly, just to push people use
804e626
the upstream supported $anyerror.
804e626
804e626
Resolves: #1129703
804e626
Related: #759132
804e626
e6ae8d9
Adjusted for tcsh-6.19.00 by Fridolin Pokorny <fpokorny@redhat.com>
e6ae8d9
804e626
---
804e626
 sh.c               |  2 ++
804e626
 sh.h               |  1 +
804e626
 sh.proc.c          |  2 +-
804e626
 sh.set.c           |  5 +++++
804e626
 tc.const.c         |  2 ++
804e626
 tests/variables.at | 28 ++++++++++++++++++++++++++++
804e626
 6 files changed, 39 insertions(+), 1 deletion(-)
804e626
804e626
diff --git a/sh.c b/sh.c
e6ae8d9
index b760f04..242556a 100644
804e626
--- a/sh.c
804e626
+++ b/sh.c
e6ae8d9
@@ -355,6 +355,8 @@ main(int argc, char **argv)
804e626
     anyerror = 1;		/* for compatibility */
804e626
     setcopy(STRanyerror, STRNULL, VAR_READWRITE);
804e626
 
804e626
+    tcsh_posix_status = 0;
804e626
+
804e626
     /* Default history size to 100 */
804e626
     setcopy(STRhistory, str2short("100"), VAR_READWRITE);
e6ae8d9
     sethistory(100);
804e626
 
804e626
diff --git a/sh.h b/sh.h
804e626
index 4e3f13c..74b7719 100644
804e626
--- a/sh.h
804e626
+++ b/sh.h
804e626
@@ -597,6 +597,7 @@ EXTERN int    editing IZERO;	/* doing filename expansion and line editing */
804e626
 EXTERN int    noediting IZERO;	/* initial $term defaulted to noedit */
804e626
 EXTERN int    bslash_quote IZERO;/* PWP: tcsh-style quoting?  (in sh.c) */
804e626
 EXTERN int    anyerror IZERO;	/* propagate errors from pipelines/backq */
804e626
+EXTERN int    tcsh_posix_status	IZERO;	/* negation for anyerror */
804e626
 EXTERN int    compat_expr IZERO;/* csh-style expressions? */
804e626
 EXTERN int    isoutatty IZERO;	/* is SHOUT a tty */
804e626
 EXTERN int    isdiagatty IZERO;/* is SHDIAG a tty */
804e626
diff --git a/sh.proc.c b/sh.proc.c
804e626
index f2356d1..e32ebda 100644
804e626
--- a/sh.proc.c
804e626
+++ b/sh.proc.c
804e626
@@ -560,7 +560,7 @@ pjwait(struct process *pp)
804e626
     do {
804e626
 	/* In case of pipelines only the result of the last
804e626
 	 * command should be taken in account */
804e626
-	if (!anyerror && !(fp->p_flags & PBRACE)
804e626
+	if ((!anyerror || tcsh_posix_status) && !(fp->p_flags & PBRACE)
804e626
 		&& ((fp->p_flags & PPOU) || (fp->p_flags & PBACKQ)))
804e626
 	    continue;
804e626
 	if (fp->p_reason)
804e626
diff --git a/sh.set.c b/sh.set.c
804e626
index 0f98a2b..8d660e0 100644
804e626
--- a/sh.set.c
804e626
+++ b/sh.set.c
804e626
@@ -109,6 +109,9 @@ update_vars(Char *vp)
804e626
     else if (eq(vp, STRanyerror)) {
804e626
 	anyerror = 1;
804e626
     }
804e626
+    else if (eq(vp, STRtcsh_posix_status)) {
804e626
+	tcsh_posix_status = 1;
804e626
+    }
804e626
     else if (eq(vp, STRsymlinks)) {
804e626
 	Char *pn = varval(vp);
804e626
 
804e626
@@ -768,6 +771,8 @@ unset(Char **v, struct command *c)
804e626
 	loginsh = 0;
804e626
     if (adrof(STRanyerror) == 0)
804e626
 	anyerror = 0;
804e626
+    if (adrof(STRtcsh_posix_status) == 0)
804e626
+	tcsh_posix_status = 0;
804e626
     if (adrof(STRwordchars) == 0)
804e626
 	word_chars = STR_WORD_CHARS;
804e626
     if (adrof(STRedit) == 0)
804e626
diff --git a/tc.const.c b/tc.const.c
804e626
index 641e234..d942542 100644
804e626
--- a/tc.const.c
804e626
+++ b/tc.const.c
804e626
@@ -44,6 +44,8 @@ Char STRrootdefautologout[] = { '1', '5', '\0' };
804e626
 Char STRautomatic[]	= { 'a', 'u', 't', 'o', 'm', 'a', 't', 'i', 'c',
804e626
 			    '\0' };
804e626
 Char STRanyerror[]	= { 'a', 'n', 'y', 'e', 'r', 'r', 'o', 'r', '\0' };
804e626
+Char STRtcsh_posix_status[] = {'t', 'c', 's', 'h', '_', 'p', 'o', 's', 'i', 'x',
804e626
+			       '_', 's', 't', 'a', 't', 'u', 's', '\0' };
804e626
 Char STRhangup[]	= { 'h', 'a', 'n', 'g', 'u', 'p', '\0' };
804e626
 Char STRaout[]		= { 'a', '.', 'o', 'u', 't', '\0' };
804e626
 Char STRtty[]		= { 't', 't', 'y', '\0' };
804e626
diff --git a/tests/variables.at b/tests/variables.at
804e626
index 424e4da..f270e59 100644
804e626
--- a/tests/variables.at
804e626
+++ b/tests/variables.at
804e626
@@ -937,6 +937,34 @@ AT_CHECK([tcsh -f -c 'echo $?tcsh'], ,
804e626
 AT_CLEANUP
804e626
 
804e626
 
804e626
+AT_SETUP([$ tcsh_posix_status])
804e626
+
804e626
+AT_DATA([exit_status.csh],
804e626
+[[echo $?tcsh_posix_status
804e626
+false | true ; echo $?
804e626
+set tcsh_posix_status = 1 ; echo $?tcsh_posix_status $tcsh_posix_status
804e626
+false | true ; echo $?
804e626
+set tcsh_posix_status = 0 ; echo $?tcsh_posix_status $tcsh_posix_status
804e626
+# Note it is still set!
804e626
+false | true ; echo $?
804e626
+unset tcsh_posix_status ; echo $?tcsh_posix_status
804e626
+false | true ; echo $?
804e626
+]])
804e626
+
804e626
+AT_CHECK([tcsh -f exit_status.csh],,
804e626
+[0
804e626
+1
804e626
+1 1
804e626
+0
804e626
+1 0
804e626
+0
804e626
+0
804e626
+1
804e626
+])
804e626
+
804e626
+AT_CLEANUP
804e626
+
804e626
+
804e626
 AT_SETUP([$ term])
804e626
 
804e626
 AT_DATA([term.csh],
804e626
-- 
804e626
1.9.3
804e626