diff --git a/check.t b/check.t index f5a95ce..8ba1d61 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.539 2012/06/25 16:05:08 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.540 2012/06/25 16:17:51 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 $ @@ -79,6 +79,19 @@ category: disabled stdin: set --- +name: selftest-legacy +description: + Check some things in the LEGACY KSH +category: shell:legacy-yes +stdin: + (set -o emacs); echo 1 = $? . + (set -o vi); echo 2 = $? . +expected-stdout: + 1 = 1 . + 2 = 1 . +expected-stderr-pattern: + /set: emacs: bad option\n.*set: vi: bad option/ +--- name: selftest-direct-builtin-call description: Check that direct builtin calls work @@ -4088,6 +4101,7 @@ description: but not 0 according to the getopt(1) manual page, ksh88, and Bourne sh (such as /bin/sh on Solaris). In mksh R39b, we honour POSIX except when -o sh is set. +category: shell:legacy-no stdin: showf() { [[ -o posix ]]; FPOSIX=$((1-$?)) @@ -4111,6 +4125,38 @@ expected-stdout: FPOSIX=0 FSH=1 rv=1 FPOSIX=1 FSH=0 rv=0 --- +name: regression-10-legacy +description: + The following: + set -- `false` + echo $? + should print 0 according to POSIX (dash, bash, ksh93, posh) + but not 0 according to the getopt(1) manual page, ksh88, and + Bourne sh (such as /bin/sh on Solaris). +category: shell:legacy-yes +stdin: + showf() { + [[ -o posix ]]; FPOSIX=$((1-$?)) + [[ -o sh ]]; FSH=$((1-$?)) + echo -n "FPOSIX=$FPOSIX FSH=$FSH " + } + set +o posix +o sh + showf + set -- `false` + echo rv=$? + set -o sh + showf + set -- `false` + echo rv=$? + set -o posix + showf + set -- `false` + echo rv=$? +expected-stdout: + FPOSIX=0 FSH=0 rv=0 + FPOSIX=0 FSH=1 rv=0 + FPOSIX=1 FSH=0 rv=0 +--- name: regression-11 description: The following: diff --git a/funcs.c b/funcs.c index 1b80f10..efe754f 100644 --- a/funcs.c +++ b/funcs.c @@ -38,7 +38,7 @@ #endif #endif -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.220 2012/06/24 20:00:51 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.221 2012/06/25 16:17:54 tg Exp $"); #if HAVE_KILLPG /* @@ -2407,7 +2407,11 @@ c_set(const char **wp) * if there are no command substitutions). * Switched ksh (!posix !sh) to POSIX in mksh R39b. */ +#ifdef MKSH_LEGACY_MODE + return (subst_exstat); +#else return (Flag(FSH) ? subst_exstat : 0); +#endif } int @@ -2612,6 +2616,7 @@ c_exec(const char **wp MKSH_A_UNUSED) for (i = 0; i < NUFILE; i++) { if (e->savefd[i] > 0) close(e->savefd[i]); +#ifdef MKSH_LEGACY_MODE /* * keep all file descriptors > 2 private for ksh, * but not for POSIX or legacy/kludge sh @@ -2619,6 +2624,7 @@ c_exec(const char **wp MKSH_A_UNUSED) if (!Flag(FPOSIX) && !Flag(FSH) && i > 2 && e->savefd[i]) fcntl(i, F_SETFD, FD_CLOEXEC); +#endif } e->savefd = NULL; }