defer setting exstat for eval to 0 (the one used in case shell() is empty)

until after the stuff run in shell() has had a chance to toy with $?

bug forwarded by one of our packagers, found by one of their users
This commit is contained in:
tg 2012-10-21 21:55:05 +00:00
parent 31f24a4040
commit c7419d9e6a
3 changed files with 25 additions and 8 deletions

18
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.560 2012/10/21 17:38:22 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.561 2012/10/21 21:55:01 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -29,7 +29,7 @@
# http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD
expected-stdout:
@(#)MIRBSD KSH R40 2012/10/03
@(#)MIRBSD KSH R40 2012/10/21
description:
Check version of shell.
stdin:
@ -38,7 +38,7 @@ name: KSH_VERSION
category: shell:legacy-no
---
expected-stdout:
@(#)LEGACY KSH R40 2012/10/03
@(#)LEGACY KSH R40 2012/10/21
description:
Check version of legacy shell.
stdin:
@ -5748,19 +5748,29 @@ name: exit-eval-1
description:
Check eval vs substitution exit codes (ksh93 alike)
stdin:
(exit 12)
eval $(false)
echo A $?
(exit 12)
eval ' $(false)'
echo B $?
(exit 12)
eval " $(false)"
echo C $?
(exit 12)
eval "eval $(false)"
echo D $?
(exit 12)
eval 'eval '"$(false)"
echo E $?
IFS="$IFS:"
(exit 12)
eval $(echo :; false)
echo F $?
echo -n "G "
(exit 12)
eval 'echo $?'
echo H $?
expected-stdout:
A 0
B 1
@ -5768,6 +5778,8 @@ expected-stdout:
D 0
E 0
F 0
G 12
H 0
---
name: exit-trap-1
description:

11
funcs.c
View File

@ -38,7 +38,7 @@
#endif
#endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.227 2012/10/21 21:39:02 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.228 2012/10/21 21:55:03 tg Exp $");
#if HAVE_KILLPG
/*
@ -2210,8 +2210,10 @@ c_eval(const char **wp)
* If there are no arguments, or only null arguments,
* eval shall return a zero exit status; ...
*/
/* exstat = subst_exstat; */ /* AT&T ksh88 */
exstat = 0; /* SUSv4 */
/* AT&T ksh88: use subst_exstat */
/* exstat = subst_exstat; */
/* SUSv4: OR with a high value never written otherwise */
exstat |= 0x4000;
savef = Flag(FERREXIT);
Flag(FERREXIT) = 0;
@ -2219,6 +2221,9 @@ c_eval(const char **wp)
Flag(FERREXIT) = savef;
source = saves;
afree(s, ATEMP);
if (exstat & 0x4000)
/* detect old exstat, use 0 in that case */
rv = 0;
return (rv);
}

4
sh.h
View File

@ -157,9 +157,9 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.594 2012/10/21 21:39:05 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.595 2012/10/21 21:55:05 tg Exp $");
#endif
#define MKSH_VERSION "R40 2012/10/03"
#define MKSH_VERSION "R40 2012/10/21"
/* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES