From ae6cc6493f128383b6d4b4673a6e1edae90ae4ed Mon Sep 17 00:00:00 2001 From: YONETANI Tomokazu Date: Fri, 12 May 2006 01:56:11 +0000 Subject: [PATCH] Merge revisions 1.38,1.41 of eval.c from FreeBSD: PR 28852 sh -e behaviour was incorrect when && and || statements where used in "if" clauses. revision 1.41 is a fix to a bug in 1.38 that subshells could lose a non-zero status. dfly problem reported-by: Johannes Hofmann OK'ed: dillon@, joerg@ --- bin/sh/eval.c | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/bin/sh/eval.c b/bin/sh/eval.c index fb29580db2..ba13595dfd 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -35,7 +35,7 @@ * * @(#)eval.c 8.9 (Berkeley) 6/8/95 * $FreeBSD: src/bin/sh/eval.c,v 1.27.2.5 2002/08/27 01:36:28 tjr Exp $ - * $DragonFly: src/bin/sh/eval.c,v 1.4 2004/03/19 18:39:41 cpressey Exp $ + * $DragonFly: src/bin/sh/eval.c,v 1.5 2006/05/12 01:56:11 y0netan1 Exp $ */ #include /* For WIFSIGNALED(status) */ @@ -202,7 +202,6 @@ evaltree(union node *n, int flags) case NAND: evaltree(n->nbinary.ch1, EV_TESTED); if (evalskip || exitstatus != 0) { - flags |= EV_TESTED; goto out; } evaltree(n->nbinary.ch2, flags); @@ -243,25 +242,9 @@ evaltree(union node *n, int flags) break; case NFOR: evalfor(n); - /* - * The 'for' command does not set exitstatus, so the value - * now in exitstatus is from the last command executed in - * the 'for' loop. That exit value had been tested (wrt - * 'sh -e' checking) while processing that command, and - * it should not be re-tested here. - */ - flags |= EV_TESTED; break; case NCASE: evalcase(n, flags); - /* - * The 'case' command does not set exitstatus, so the value - * now in exitstatus is from the last command executed in - * the 'case' block. That exit value had been tested (wrt - * 'sh -e' checking) while processing that command, and - * it should not be re-tested here. - */ - flags |= EV_TESTED; break; case NDEFUN: defun(n->narg.text, n->narg.next); @@ -286,14 +269,9 @@ evaltree(union node *n, int flags) out: if (pendingsigs) dotrap(); - /* - * XXX - Like "!(n->type == NSEMI)", more types will probably - * need to be excluded from this test. It's probably better - * to set or unset EV_TESTED in the loop above than to bloat - * the conditional here. - */ if ((flags & EV_EXIT) || (eflag && exitstatus - && !(flags & EV_TESTED) && !(n->type == NSEMI))) + && !(flags & EV_TESTED) && (n->type == NCMD || + n->type == NSUBSHELL))) exitshell(exitstatus); } -- 2.28.0