From f21d6a3ffd538f7489b4bab42618819a18e0b186 Mon Sep 17 00:00:00 2001 From: tg Date: Thu, 28 Jul 2016 21:39:19 +0000 Subject: [PATCH] =?UTF-8?q?fix=20(POSIX)=20errorlevel=20of=20=E2=80=98.?= =?UTF-8?q?=E2=80=99=20when=20sourced=20file=20has=20no=20commands;=20issu?= =?UTF-8?q?e=20discovered=20by=20Natureshadow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- check.t | 17 ++++++++++++++--- funcs.c | 13 +++++++++---- sh.h | 4 ++-- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/check.t b/check.t index 32f945f..9341cf0 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.745 2016/07/26 21:50:42 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.746 2016/07/28 21:39:16 tg Exp $ # -*- mode: sh -*- #- # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, @@ -30,7 +30,7 @@ # (2013/12/02 20:39:44) http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date expected-stdout: - @(#)MIRBSD KSH R53 2016/07/26 + @(#)MIRBSD KSH R53 2016/07/28 description: Check version of shell. stdin: @@ -39,7 +39,7 @@ name: KSH_VERSION category: shell:legacy-no --- expected-stdout: - @(#)LEGACY KSH R53 2016/07/26 + @(#)LEGACY KSH R53 2016/07/28 description: Check version of legacy shell. stdin: @@ -9326,6 +9326,17 @@ expected-exit: e != 0 expected-stderr-pattern: /\.: missing argument.*\n.*source: missing argument/ --- +name: dot-errorlevel +description: + Ensure dot resets $? +stdin: + :>dotfile + (exit 42) + . ./dotfile + echo 1 $? . +expected-stdout: + 1 0 . +--- name: alias-function-no-conflict description: make aliases not conflict with function definitions diff --git a/funcs.c b/funcs.c index 26c4f04..10c62a2 100644 --- a/funcs.c +++ b/funcs.c @@ -38,7 +38,7 @@ #endif #endif -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.302 2016/07/26 21:50:44 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.303 2016/07/28 21:39:18 tg Exp $"); #if HAVE_KILLPG /* @@ -1806,7 +1806,7 @@ int c_dot(const char **wp) { const char *file, *cp, **argv; - int argc, i, errcode; + int argc, rv, errcode; if (ksh_getopt(wp, &builtin_opt, null) == '?') return (1); @@ -1835,12 +1835,17 @@ c_dot(const char **wp) argc = 0; argv = NULL; } - if ((i = include(file, argc, argv, false)) < 0) { + /* SUSv4: OR with a high value never written otherwise */ + exstat |= 0x4000; + if ((rv = include(file, argc, argv, false)) < 0) { /* should not happen */ bi_errorf(Tf_sD_s, cp, cstrerror(errno)); return (1); } - return (i); + if (exstat & 0x4000) + /* detect old exstat, use 0 in that case */ + rv = 0; + return (rv); } int diff --git a/sh.h b/sh.h index cebeeab..f9e0811 100644 --- a/sh.h +++ b/sh.h @@ -175,9 +175,9 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.780 2016/07/26 21:50:46 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.781 2016/07/28 21:39:19 tg Exp $"); #endif -#define MKSH_VERSION "R53 2016/07/26" +#define MKSH_VERSION "R53 2016/07/28" /* arithmetic types: C implementation */ #if !HAVE_CAN_INTTYPES