fix (POSIX) errorlevel of ‘.’ when sourced file has no commands; issue discovered by Natureshadow

This commit is contained in:
tg 2016-07-28 21:39:19 +00:00
parent b8180fba1f
commit f21d6a3ffd
3 changed files with 25 additions and 9 deletions

17
check.t
View File

@ -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

13
funcs.c
View File

@ -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

4
sh.h
View File

@ -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