Merge remote-tracking branch 'mksh/master'

Conflicts:
	check.t
	main.c
This commit is contained in:
KO Myung-Hun 2015-08-15 23:23:55 +09:00
commit df20ee1fff
8 changed files with 72 additions and 122 deletions

89
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.703 2015/07/10 19:36:31 tg Exp $ # $MirOS: src/bin/mksh/check.t,v 1.705 2015/08/13 22:06:19 tg Exp $
# -*- mode: sh -*- # -*- mode: sh -*-
#- #-
# Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
@ -30,7 +30,7 @@
# (2013/12/02 20:39:44) http://openbsd.cs.toronto.edu/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date # (2013/12/02 20:39:44) http://openbsd.cs.toronto.edu/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date
expected-stdout: expected-stdout:
@(#)MIRBSD KSH R51 2015/07/10 @(#)MIRBSD KSH R51 2015/08/13
description: description:
Check version of shell. Check version of shell.
stdin: stdin:
@ -39,7 +39,7 @@ name: KSH_VERSION
category: shell:legacy-no category: shell:legacy-no
--- ---
expected-stdout: expected-stdout:
@(#)LEGACY KSH R51 2015/07/10 @(#)LEGACY KSH R51 2015/08/13
description: description:
Check version of legacy shell. Check version of legacy shell.
stdin: stdin:
@ -7466,7 +7466,7 @@ expected-stdout:
nameref='\typeset -n' nameref='\typeset -n'
nohup='nohup ' nohup='nohup '
r='\builtin fc -e -' r='\builtin fc -e -'
source='PATH="$PATH:." \command .' source='PATH=$PATH:. \command .'
stop='\kill -STOP' stop='\kill -STOP'
type='\builtin whence -v' type='\builtin whence -v'
--- ---
@ -7488,28 +7488,7 @@ expected-stdout:
nameref='\typeset -n' nameref='\typeset -n'
nohup='nohup ' nohup='nohup '
r='\builtin fc -e -' r='\builtin fc -e -'
source='PATH="$PATH:." \command .' source='PATH=$PATH:. \command .'
type='\builtin whence -v'
---
name: aliases-1-hartz4-semi
description:
Check if built-in shell aliases are okay
category: os:os2
stdin:
alias
typeset -f
expected-stdout:
autoload='\typeset -fu'
functions='\typeset -f'
hash='\builtin alias -t'
history='\builtin fc -l'
integer='\typeset -i'
local='\typeset'
login='\exec login'
nameref='\typeset -n'
nohup='nohup '
r='\builtin fc -e -'
source='PATH="$PATH;." \command .'
type='\builtin whence -v' type='\builtin whence -v'
--- ---
name: aliases-1-os2 name: aliases-1-os2
@ -7530,7 +7509,7 @@ expected-stdout:
nameref='\typeset -n' nameref='\typeset -n'
nohup='nohup ' nohup='nohup '
r='\builtin fc -e -' r='\builtin fc -e -'
source='PATH="$PATH;." \command .' source='PATH=$PATH\;. \command .'
type='\builtin whence -v' type='\builtin whence -v'
--- ---
name: aliases-2b name: aliases-2b
@ -7552,7 +7531,7 @@ expected-stdout:
nameref='\typeset -n' nameref='\typeset -n'
nohup='nohup ' nohup='nohup '
r='\builtin fc -e -' r='\builtin fc -e -'
source='PATH="$PATH:." \command .' source='PATH=$PATH:. \command .'
stop='\kill -STOP' stop='\kill -STOP'
type='\builtin whence -v' type='\builtin whence -v'
--- ---
@ -7575,7 +7554,7 @@ expected-stdout:
nameref='\typeset -n' nameref='\typeset -n'
nohup='nohup ' nohup='nohup '
r='\builtin fc -e -' r='\builtin fc -e -'
source='PATH="$PATH:." \command .' source='PATH=$PATH:. \command .'
stop='\kill -STOP' stop='\kill -STOP'
type='\builtin whence -v' type='\builtin whence -v'
--- ---
@ -7598,7 +7577,7 @@ expected-stdout:
nameref='\typeset -n' nameref='\typeset -n'
nohup='nohup ' nohup='nohup '
r='\builtin fc -e -' r='\builtin fc -e -'
source='PATH="$PATH:." \command .' source='PATH=$PATH:. \command .'
type='\builtin whence -v' type='\builtin whence -v'
--- ---
name: aliases-3b-hartz4 name: aliases-3b-hartz4
@ -7620,51 +7599,7 @@ expected-stdout:
nameref='\typeset -n' nameref='\typeset -n'
nohup='nohup ' nohup='nohup '
r='\builtin fc -e -' r='\builtin fc -e -'
source='PATH="$PATH:." \command .' source='PATH=$PATH:. \command .'
type='\builtin whence -v'
---
name: aliases-2b-hartz4-semi
description:
Check if set -o sh does not influence built-in aliases
category: os:os2
arguments: !-o!sh!
stdin:
alias
typeset -f
expected-stdout:
autoload='\typeset -fu'
functions='\typeset -f'
hash='\builtin alias -t'
history='\builtin fc -l'
integer='\typeset -i'
local='\typeset'
login='\exec login'
nameref='\typeset -n'
nohup='nohup '
r='\builtin fc -e -'
source='PATH="$PATH;." \command .'
type='\builtin whence -v'
---
name: aliases-3b-hartz4-semi
description:
Check if running as sh does not influence built-in aliases
category: os:os2
stdin:
cp "$__progname" sh
./sh -c 'alias; typeset -f'
rm -f sh
expected-stdout:
autoload='\typeset -fu'
functions='\typeset -f'
hash='\builtin alias -t'
history='\builtin fc -l'
integer='\typeset -i'
local='\typeset'
login='\exec login'
nameref='\typeset -n'
nohup='nohup '
r='\builtin fc -e -'
source='PATH="$PATH;." \command .'
type='\builtin whence -v' type='\builtin whence -v'
--- ---
name: aliases-2b-os2 name: aliases-2b-os2
@ -7686,7 +7621,7 @@ expected-stdout:
nameref='\typeset -n' nameref='\typeset -n'
nohup='nohup ' nohup='nohup '
r='\builtin fc -e -' r='\builtin fc -e -'
source='PATH="$PATH;." \command .' source='PATH=$PATH\;. \command .'
type='\builtin whence -v' type='\builtin whence -v'
--- ---
name: aliases-3b-os2 name: aliases-3b-os2
@ -7708,7 +7643,7 @@ expected-stdout:
nameref='\typeset -n' nameref='\typeset -n'
nohup='nohup ' nohup='nohup '
r='\builtin fc -e -' r='\builtin fc -e -'
source='PATH="$PATH;." \command .' source='PATH=$PATH\;. \command .'
type='\builtin whence -v' type='\builtin whence -v'
--- ---
name: aliases-cmdline name: aliases-cmdline

14
funcs.c
View File

@ -1,5 +1,5 @@
/* $OpenBSD: c_ksh.c,v 1.34 2013/12/17 16:37:05 deraadt Exp $ */ /* $OpenBSD: c_ksh.c,v 1.34 2013/12/17 16:37:05 deraadt Exp $ */
/* $OpenBSD: c_sh.c,v 1.45 2014/08/27 08:26:04 jmc Exp $ */ /* $OpenBSD: c_sh.c,v 1.46 2015/07/20 20:46:24 guenther Exp $ */
/* $OpenBSD: c_test.c,v 1.18 2009/03/01 20:11:06 otto Exp $ */ /* $OpenBSD: c_test.c,v 1.18 2009/03/01 20:11:06 otto Exp $ */
/* $OpenBSD: c_ulimit.c,v 1.19 2013/11/28 10:33:37 sobrado Exp $ */ /* $OpenBSD: c_ulimit.c,v 1.19 2013/11/28 10:33:37 sobrado Exp $ */
@ -38,7 +38,7 @@
#endif #endif
#endif #endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.280 2015/07/09 20:52:39 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.282 2015/08/13 21:38:17 tg Exp $");
#if HAVE_KILLPG #if HAVE_KILLPG
/* /*
@ -1374,7 +1374,7 @@ c_kill(const char **wp)
for (; wp[i]; i++) { for (; wp[i]; i++) {
if (!bi_getn(wp[i], &n)) if (!bi_getn(wp[i], &n))
return (1); return (1);
#if (ksh_NSIG < 128) #if (ksh_NSIG <= 128)
if (n > 128 && n < 128 + ksh_NSIG) if (n > 128 && n < 128 + ksh_NSIG)
n -= 128; n -= 128;
#endif #endif
@ -1385,7 +1385,7 @@ c_kill(const char **wp)
} }
} else { } else {
ssize_t w, mess_cols = 0, mess_octs = 0; ssize_t w, mess_cols = 0, mess_octs = 0;
int j = ksh_NSIG; int j = ksh_NSIG - 1;
struct kill_info ki = { 0, 0 }; struct kill_info ki = { 0, 0 };
do { do {
@ -2293,7 +2293,7 @@ int
c_trap(const char **wp) c_trap(const char **wp)
{ {
Trap *p = sigtraps; Trap *p = sigtraps;
int i = ksh_NSIG + 1; int i = ksh_NSIG;
const char *s; const char *s;
if (ksh_getopt(wp, &builtin_opt, null) == '?') if (ksh_getopt(wp, &builtin_opt, null) == '?')
@ -2308,7 +2308,7 @@ c_trap(const char **wp)
shprintf(" %s\n", p->name); shprintf(" %s\n", p->name);
} }
++p; ++p;
} while (--i); } while (i--);
return (0); return (0);
} }
@ -2542,7 +2542,7 @@ p_time(struct shf *shf, bool posix, long tv_sec, int tv_usec, int width,
shf_fprintf(shf, "%s%*ld.%02d%s", prefix, width, shf_fprintf(shf, "%s%*ld.%02d%s", prefix, width,
tv_sec, tv_usec, suffix); tv_sec, tv_usec, suffix);
else else
shf_fprintf(shf, "%s%*ldm%d.%02ds%s", prefix, width, shf_fprintf(shf, "%s%*ldm%02d.%02ds%s", prefix, width,
tv_sec / 60, (int)(tv_sec % 60), tv_usec, suffix); tv_sec / 60, (int)(tv_sec % 60), tv_usec, suffix);
} }

57
jobs.c
View File

@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.112 2015/04/19 14:40:09 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.113 2015/08/13 21:38:19 tg Exp $");
#if HAVE_KILLPG #if HAVE_KILLPG
#define mksh_killpg killpg #define mksh_killpg killpg
@ -215,11 +215,14 @@ j_init(void)
static int static int
proc_errorlevel(Proc *p) proc_errorlevel(Proc *p)
{ {
int termsig;
switch (p->state) { switch (p->state) {
case PEXITED: case PEXITED:
return (WEXITSTATUS(p->status)); return ((WEXITSTATUS(p->status)) & 255);
case PSIGNALLED: case PSIGNALLED:
return (128 + WTERMSIG(p->status)); termsig = WTERMSIG(p->status);
return ((termsig < 1 || termsig > 127) ? 255 : 128 + termsig);
default: default:
return (0); return (0);
} }
@ -1225,14 +1228,14 @@ j_waitj(Job *j,
* even when not monitoring, but this doesn't make sense since * even when not monitoring, but this doesn't make sense since
* a tty generated ^C goes to the whole process group) * a tty generated ^C goes to the whole process group)
*/ */
{
int status;
status = j->last_proc->status;
if (Flag(FMONITOR) && j->state == PSIGNALLED && if (Flag(FMONITOR) && j->state == PSIGNALLED &&
WIFSIGNALED(status) && WIFSIGNALED(j->last_proc->status)) {
(sigtraps[WTERMSIG(status)].flags & TF_TTY_INTR)) int termsig;
trapsig(WTERMSIG(status));
if ((termsig = WTERMSIG(j->last_proc->status)) > 0 &&
termsig < ksh_NSIG &&
(sigtraps[termsig].flags & TF_TTY_INTR))
trapsig(termsig);
} }
#endif #endif
} }
@ -1531,7 +1534,7 @@ j_print(Job *j, int how, struct shf *shf)
Proc *p; Proc *p;
int state; int state;
int status; int status;
int coredumped; bool coredumped;
char jobchar = ' '; char jobchar = ' ';
char buf[64]; char buf[64];
const char *filler; const char *filler;
@ -1555,41 +1558,49 @@ j_print(Job *j, int how, struct shf *shf)
jobchar = '-'; jobchar = '-';
for (p = j->proc_list; p != NULL;) { for (p = j->proc_list; p != NULL;) {
coredumped = 0; coredumped = false;
switch (p->state) { switch (p->state) {
case PRUNNING: case PRUNNING:
memcpy(buf, "Running", 8); memcpy(buf, "Running", 8);
break; break;
case PSTOPPED: case PSTOPPED: {
strlcpy(buf, sigtraps[WSTOPSIG(p->status)].mess, int stopsig = WSTOPSIG(p->status);
sizeof(buf));
strlcpy(buf, stopsig > 0 && stopsig < ksh_NSIG ?
sigtraps[stopsig].mess : "Stopped", sizeof(buf));
break; break;
case PEXITED: }
case PEXITED: {
int exitstatus = (WEXITSTATUS(p->status)) & 255;
if (how == JP_SHORT) if (how == JP_SHORT)
buf[0] = '\0'; buf[0] = '\0';
else if (WEXITSTATUS(p->status) == 0) else if (exitstatus == 0)
memcpy(buf, "Done", 5); memcpy(buf, "Done", 5);
else else
shf_snprintf(buf, sizeof(buf), "Done (%d)", shf_snprintf(buf, sizeof(buf), "Done (%d)",
WEXITSTATUS(p->status)); exitstatus);
break; break;
case PSIGNALLED: }
case PSIGNALLED: {
int termsig = WTERMSIG(p->status);
#ifdef WCOREDUMP #ifdef WCOREDUMP
if (WCOREDUMP(p->status)) if (WCOREDUMP(p->status))
coredumped = 1; coredumped = true;
#endif #endif
/* /*
* kludge for not reporting 'normal termination * kludge for not reporting 'normal termination
* signals' (i.e. SIGINT, SIGPIPE) * signals' (i.e. SIGINT, SIGPIPE)
*/ */
if (how == JP_SHORT && !coredumped && if (how == JP_SHORT && !coredumped &&
(WTERMSIG(p->status) == SIGINT || (termsig == SIGINT || termsig == SIGPIPE)) {
WTERMSIG(p->status) == SIGPIPE)) {
buf[0] = '\0'; buf[0] = '\0';
} else } else
strlcpy(buf, sigtraps[WTERMSIG(p->status)].mess, strlcpy(buf, termsig > 0 && termsig < ksh_NSIG ?
sigtraps[termsig].mess : "Signalled",
sizeof(buf)); sizeof(buf));
break; break;
}
default: default:
buf[0] = '\0'; buf[0] = '\0';
} }

4
lex.c
View File

@ -1,4 +1,4 @@
/* $OpenBSD: lex.c,v 1.49 2013/12/17 16:37:06 deraadt Exp $ */ /* $OpenBSD: lex.c,v 1.50 2015/07/30 14:59:12 zhuk Exp $ */
/*- /*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.204 2015/07/05 19:53:46 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/lex.c,v 1.205 2015/08/13 21:04:12 tg Exp $");
/* /*
* states while lexing word * states while lexing word

4
main.c
View File

@ -34,7 +34,7 @@
#include <locale.h> #include <locale.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.300 2015/07/10 19:36:35 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/main.c,v 1.301 2015/08/13 22:06:22 tg Exp $");
extern char **environ; extern char **environ;
@ -82,7 +82,7 @@ static const char *initcoms[] = {
"nameref=\\typeset -n", "nameref=\\typeset -n",
"nohup=nohup ", "nohup=nohup ",
"r=\\builtin fc -e -", "r=\\builtin fc -e -",
"source=PATH=\"$PATH" MKSH_PATHSEPS ".\" \\command .", "source=PATH=$PATH" MKSH_PATHSEPE ". \\command .",
"login=\\exec login", "login=\\exec login",
NULL, NULL,
/* this is what AT&T ksh seems to track, with the addition of emacs */ /* this is what AT&T ksh seems to track, with the addition of emacs */

8
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.378 2015/07/12 19:09:50 tg Exp $ .\" $MirOS: src/bin/mksh/mksh.1,v 1.379 2015/08/13 22:09:10 tg Exp $
.\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $ .\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $
.\"- .\"-
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
@ -74,7 +74,7 @@
.\" with -mandoc, it might implement .Mx itself, but we want to .\" with -mandoc, it might implement .Mx itself, but we want to
.\" use our own definition. And .Dd must come *first*, always. .\" use our own definition. And .Dd must come *first*, always.
.\" .\"
.Dd $Mdocdate: July 12 2015 $ .Dd $Mdocdate: August 13 2015 $
.\" .\"
.\" Check which macro package we use, and do other -mdoc setup. .\" Check which macro package we use, and do other -mdoc setup.
.\" .\"
@ -1946,8 +1946,8 @@ Assigning 1 to this parameter causes
.Ic getopts .Ic getopts
to process arguments from the beginning the next time it is invoked. to process arguments from the beginning the next time it is invoked.
.It Ev PATH .It Ev PATH
A colon separated list of directories that are searched when looking for A colon (semicolon on OS/2) separated list of directories that are
commands and files sourced using the searched when looking for commands and files sourced using the
.Sq \&. .Sq \&.
command (see below). command (see below).
An empty string resulting from a leading or trailing An empty string resulting from a leading or trailing

14
sh.h
View File

@ -172,9 +172,9 @@
#endif #endif
#ifdef EXTERN #ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.739 2015/07/10 19:36:37 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.741 2015/08/13 22:06:23 tg Exp $");
#endif #endif
#define MKSH_VERSION "R51 2015/07/10" #define MKSH_VERSION "R51 2015/08/13"
/* arithmetic types: C implementation */ /* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES #if !HAVE_CAN_INTTYPES
@ -337,15 +337,15 @@ struct rusage {
/* determine ksh_NSIG: first, use the traditional definitions */ /* determine ksh_NSIG: first, use the traditional definitions */
#undef ksh_NSIG #undef ksh_NSIG
#if defined(NSIG) #if defined(NSIG)
#define ksh_NSIG NSIG #define ksh_NSIG (NSIG)
#elif defined(_NSIG) #elif defined(_NSIG)
#define ksh_NSIG _NSIG #define ksh_NSIG (_NSIG)
#elif defined(SIGMAX) #elif defined(SIGMAX)
#define ksh_NSIG (SIGMAX + 1) #define ksh_NSIG (SIGMAX + 1)
#elif defined(_SIGMAX) #elif defined(_SIGMAX)
#define ksh_NSIG (_SIGMAX + 1) #define ksh_NSIG (_SIGMAX + 1)
#elif defined(NSIG_MAX) #elif defined(NSIG_MAX)
#define ksh_NSIG NSIG_MAX #define ksh_NSIG (NSIG_MAX)
#else #else
# error Please have your platform define NSIG. # error Please have your platform define NSIG.
#endif #endif
@ -367,7 +367,7 @@ struct rusage {
#else #else
/* since its usable, prefer it */ /* since its usable, prefer it */
#undef ksh_NSIG #undef ksh_NSIG
#define ksh_NSIG NSIG_MAX #define ksh_NSIG (NSIG_MAX)
#endif #endif
/* if NSIG_MAX is now still defined, use sysconf(_SC_NSIG) at runtime */ /* if NSIG_MAX is now still defined, use sysconf(_SC_NSIG) at runtime */
#endif #endif
@ -387,10 +387,12 @@ struct rusage {
#endif #endif
#ifdef __OS2__ #ifdef __OS2__
#define MKSH_PATHSEPE "\\;"
#define MKSH_PATHSEPS ";" #define MKSH_PATHSEPS ";"
#define MKSH_PATHSEPC ';' #define MKSH_PATHSEPC ';'
#define MKSH_UNIXROOT "/@unixroot" #define MKSH_UNIXROOT "/@unixroot"
#else #else
#define MKSH_PATHSEPE ":"
#define MKSH_PATHSEPS ":" #define MKSH_PATHSEPS ":"
#define MKSH_PATHSEPC ':' #define MKSH_PATHSEPC ':'
#define MKSH_UNIXROOT "" #define MKSH_UNIXROOT ""

4
tree.c
View File

@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.73 2015/04/11 22:03:32 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/tree.c,v 1.74 2015/08/13 20:54:03 tg Exp $");
#define INDENT 8 #define INDENT 8
@ -748,6 +748,8 @@ fpFUNCTf(struct shf *shf, int i, bool isksh, const char *k, struct op *v)
{ {
if (isksh) if (isksh)
fptreef(shf, i, "%s %s %T", Tfunction, k, v); fptreef(shf, i, "%s %s %T", Tfunction, k, v);
else if (ktsearch(&keywords, k, hash(k)))
fptreef(shf, i, "%s %s() %T", Tfunction, k, v);
else else
fptreef(shf, i, "%s() %T", k, v); fptreef(shf, i, "%s() %T", k, v);
} }