From fdb9509fe5897e2eb1e6d3643f697426fb6b4305 Mon Sep 17 00:00:00 2001 From: tg Date: Thu, 13 Aug 2015 20:54:03 +0000 Subject: [PATCH 1/5] make 'typeset -f' output reentrant in the face of functions whose names are keywords and a GNU bash extension (gah!); reported by izabera --- tree.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tree.c b/tree.c index c057559..6a983a3 100644 --- a/tree.c +++ b/tree.c @@ -23,7 +23,7 @@ #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 @@ -748,6 +748,8 @@ fpFUNCTf(struct shf *shf, int i, bool isksh, const char *k, struct op *v) { if (isksh) 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 fptreef(shf, i, "%s() %T", k, v); } From 9d30e9c9d6da650af7433af9e059fd95768515aa Mon Sep 17 00:00:00 2001 From: tg Date: Thu, 13 Aug 2015 21:04:12 +0000 Subject: [PATCH 2/5] oksh sync: one rcsid-only plus this one by guenther: Zero-pad the seconds in the output of 'time' to make columns line up --- funcs.c | 6 +++--- lex.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/funcs.c b/funcs.c index 0d2aec3..643bde6 100644 --- a/funcs.c +++ b/funcs.c @@ -1,5 +1,5 @@ /* $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_ulimit.c,v 1.19 2013/11/28 10:33:37 sobrado Exp $ */ @@ -38,7 +38,7 @@ #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.281 2015/08/13 21:04:11 tg Exp $"); #if HAVE_KILLPG /* @@ -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, tv_sec, tv_usec, suffix); 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); } diff --git a/lex.c b/lex.c index fb80244..f5f38f7 100644 --- a/lex.c +++ b/lex.c @@ -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, @@ -23,7 +23,7 @@ #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 From c674e713770b77c43bbc994745ee968fcd4890f0 Mon Sep 17 00:00:00 2001 From: tg Date: Thu, 13 Aug 2015 21:38:19 +0000 Subject: [PATCH 3/5] =?UTF-8?q?be=20more=20careful=20with=20signals=20and?= =?UTF-8?q?=20errorlevels;=20bounds-check=20them=20better;=20don=E2=80=99t?= =?UTF-8?q?=20trust=20the=20OS=20as=20POSuX=20comes=20up=20with=20more-tha?= =?UTF-8?q?n-8-bit=20exit=20codes=20now;=20also,=20one=20more=20int=20?= =?UTF-8?q?=E2=86=92=20bool?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- check.t | 6 +++--- funcs.c | 10 +++++----- jobs.c | 57 ++++++++++++++++++++++++++++++++++----------------------- sh.h | 12 ++++++------ 4 files changed, 48 insertions(+), 37 deletions(-) diff --git a/check.t b/check.t index 989722b..d45f97f 100644 --- a/check.t +++ b/check.t @@ -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.704 2015/08/13 21:38:15 tg Exp $ # -*- mode: sh -*- #- # 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 expected-stdout: - @(#)MIRBSD KSH R51 2015/07/10 + @(#)MIRBSD KSH R51 2015/08/13 description: Check version of shell. stdin: @@ -39,7 +39,7 @@ name: KSH_VERSION category: shell:legacy-no --- expected-stdout: - @(#)LEGACY KSH R51 2015/07/10 + @(#)LEGACY KSH R51 2015/08/13 description: Check version of legacy shell. stdin: diff --git a/funcs.c b/funcs.c index 643bde6..a408bb0 100644 --- a/funcs.c +++ b/funcs.c @@ -38,7 +38,7 @@ #endif #endif -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.281 2015/08/13 21:04:11 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.282 2015/08/13 21:38:17 tg Exp $"); #if HAVE_KILLPG /* @@ -1374,7 +1374,7 @@ c_kill(const char **wp) for (; wp[i]; i++) { if (!bi_getn(wp[i], &n)) return (1); -#if (ksh_NSIG < 128) +#if (ksh_NSIG <= 128) if (n > 128 && n < 128 + ksh_NSIG) n -= 128; #endif @@ -1385,7 +1385,7 @@ c_kill(const char **wp) } } else { ssize_t w, mess_cols = 0, mess_octs = 0; - int j = ksh_NSIG; + int j = ksh_NSIG - 1; struct kill_info ki = { 0, 0 }; do { @@ -2293,7 +2293,7 @@ int c_trap(const char **wp) { Trap *p = sigtraps; - int i = ksh_NSIG + 1; + int i = ksh_NSIG; const char *s; if (ksh_getopt(wp, &builtin_opt, null) == '?') @@ -2308,7 +2308,7 @@ c_trap(const char **wp) shprintf(" %s\n", p->name); } ++p; - } while (--i); + } while (i--); return (0); } diff --git a/jobs.c b/jobs.c index 8469f83..3771623 100644 --- a/jobs.c +++ b/jobs.c @@ -23,7 +23,7 @@ #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 #define mksh_killpg killpg @@ -215,11 +215,14 @@ j_init(void) static int proc_errorlevel(Proc *p) { + int termsig; + switch (p->state) { case PEXITED: - return (WEXITSTATUS(p->status)); + return ((WEXITSTATUS(p->status)) & 255); case PSIGNALLED: - return (128 + WTERMSIG(p->status)); + termsig = WTERMSIG(p->status); + return ((termsig < 1 || termsig > 127) ? 255 : 128 + termsig); default: return (0); } @@ -1223,14 +1226,14 @@ j_waitj(Job *j, * even when not monitoring, but this doesn't make sense since * a tty generated ^C goes to the whole process group) */ - { - int status; + if (Flag(FMONITOR) && j->state == PSIGNALLED && + WIFSIGNALED(j->last_proc->status)) { + int termsig; - status = j->last_proc->status; - if (Flag(FMONITOR) && j->state == PSIGNALLED && - WIFSIGNALED(status) && - (sigtraps[WTERMSIG(status)].flags & TF_TTY_INTR)) - trapsig(WTERMSIG(status)); + if ((termsig = WTERMSIG(j->last_proc->status)) > 0 && + termsig < ksh_NSIG && + (sigtraps[termsig].flags & TF_TTY_INTR)) + trapsig(termsig); } #endif } @@ -1527,7 +1530,7 @@ j_print(Job *j, int how, struct shf *shf) Proc *p; int state; int status; - int coredumped; + bool coredumped; char jobchar = ' '; char buf[64]; const char *filler; @@ -1551,41 +1554,49 @@ j_print(Job *j, int how, struct shf *shf) jobchar = '-'; for (p = j->proc_list; p != NULL;) { - coredumped = 0; + coredumped = false; switch (p->state) { case PRUNNING: memcpy(buf, "Running", 8); break; - case PSTOPPED: - strlcpy(buf, sigtraps[WSTOPSIG(p->status)].mess, - sizeof(buf)); + case PSTOPPED: { + int stopsig = WSTOPSIG(p->status); + + strlcpy(buf, stopsig > 0 && stopsig < ksh_NSIG ? + sigtraps[stopsig].mess : "Stopped", sizeof(buf)); break; - case PEXITED: + } + case PEXITED: { + int exitstatus = (WEXITSTATUS(p->status)) & 255; + if (how == JP_SHORT) buf[0] = '\0'; - else if (WEXITSTATUS(p->status) == 0) + else if (exitstatus == 0) memcpy(buf, "Done", 5); else shf_snprintf(buf, sizeof(buf), "Done (%d)", - WEXITSTATUS(p->status)); + exitstatus); break; - case PSIGNALLED: + } + case PSIGNALLED: { + int termsig = WTERMSIG(p->status); #ifdef WCOREDUMP if (WCOREDUMP(p->status)) - coredumped = 1; + coredumped = true; #endif /* * kludge for not reporting 'normal termination * signals' (i.e. SIGINT, SIGPIPE) */ if (how == JP_SHORT && !coredumped && - (WTERMSIG(p->status) == SIGINT || - WTERMSIG(p->status) == SIGPIPE)) { + (termsig == SIGINT || termsig == SIGPIPE)) { buf[0] = '\0'; } else - strlcpy(buf, sigtraps[WTERMSIG(p->status)].mess, + strlcpy(buf, termsig > 0 && termsig < ksh_NSIG ? + sigtraps[termsig].mess : "Signalled", sizeof(buf)); break; + } default: buf[0] = '\0'; } diff --git a/sh.h b/sh.h index c3109e5..78cc82c 100644 --- a/sh.h +++ b/sh.h @@ -172,9 +172,9 @@ #endif #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.740 2015/08/13 21:38:19 tg Exp $"); #endif -#define MKSH_VERSION "R51 2015/07/10" +#define MKSH_VERSION "R51 2015/08/13" /* arithmetic types: C implementation */ #if !HAVE_CAN_INTTYPES @@ -337,15 +337,15 @@ struct rusage { /* determine ksh_NSIG: first, use the traditional definitions */ #undef ksh_NSIG #if defined(NSIG) -#define ksh_NSIG NSIG +#define ksh_NSIG (NSIG) #elif defined(_NSIG) -#define ksh_NSIG _NSIG +#define ksh_NSIG (_NSIG) #elif defined(SIGMAX) #define ksh_NSIG (SIGMAX + 1) #elif defined(_SIGMAX) #define ksh_NSIG (_SIGMAX + 1) #elif defined(NSIG_MAX) -#define ksh_NSIG NSIG_MAX +#define ksh_NSIG (NSIG_MAX) #else # error Please have your platform define NSIG. #endif @@ -367,7 +367,7 @@ struct rusage { #else /* since it’s usable, prefer it */ #undef ksh_NSIG -#define ksh_NSIG NSIG_MAX +#define ksh_NSIG (NSIG_MAX) #endif /* if NSIG_MAX is now still defined, use sysconf(_SC_NSIG) at runtime */ #endif From 1b8b792b7e1a41fdf13f95df43926e6e3b74acae Mon Sep 17 00:00:00 2001 From: tg Date: Thu, 13 Aug 2015 22:06:23 +0000 Subject: [PATCH 4/5] quote path separator if ; in some cases; pointed out by komh --- check.t | 8 ++++---- main.c | 4 ++-- sh.h | 4 +++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/check.t b/check.t index d45f97f..03b19e8 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.704 2015/08/13 21:38:15 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.705 2015/08/13 22:06:19 tg Exp $ # -*- mode: sh -*- #- # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, @@ -7509,7 +7509,7 @@ expected-stdout: nameref='\typeset -n' nohup='nohup ' r='\builtin fc -e -' - source='PATH=$PATH;. \command .' + source='PATH=$PATH\;. \command .' type='\builtin whence -v' --- name: aliases-2b @@ -7621,7 +7621,7 @@ expected-stdout: nameref='\typeset -n' nohup='nohup ' r='\builtin fc -e -' - source='PATH=$PATH;. \command .' + source='PATH=$PATH\;. \command .' type='\builtin whence -v' --- name: aliases-3b-os2 @@ -7643,7 +7643,7 @@ expected-stdout: nameref='\typeset -n' nohup='nohup ' r='\builtin fc -e -' - source='PATH=$PATH;. \command .' + source='PATH=$PATH\;. \command .' type='\builtin whence -v' --- name: aliases-cmdline diff --git a/main.c b/main.c index bca8471..dad2619 100644 --- a/main.c +++ b/main.c @@ -34,7 +34,7 @@ #include #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; @@ -82,7 +82,7 @@ static const char *initcoms[] = { "nameref=\\typeset -n", "nohup=nohup ", "r=\\builtin fc -e -", - "source=PATH=$PATH" MKSH_PATHSEPS ". \\command .", + "source=PATH=$PATH" MKSH_PATHSEPE ". \\command .", "login=\\exec login", NULL, /* this is what AT&T ksh seems to track, with the addition of emacs */ diff --git a/sh.h b/sh.h index 78cc82c..27d5c0a 100644 --- a/sh.h +++ b/sh.h @@ -172,7 +172,7 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.740 2015/08/13 21:38:19 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.741 2015/08/13 22:06:23 tg Exp $"); #endif #define MKSH_VERSION "R51 2015/08/13" @@ -387,10 +387,12 @@ struct rusage { #endif #ifdef __OS2__ +#define MKSH_PATHSEPE "\\;" #define MKSH_PATHSEPS ";" #define MKSH_PATHSEPC ';' #define MKSH_UNIXROOT "/@unixroot" #else +#define MKSH_PATHSEPE ":" #define MKSH_PATHSEPS ":" #define MKSH_PATHSEPC ':' #define MKSH_UNIXROOT "" From 92978953b2d6923273ef0af43594acdbfa9f3bea Mon Sep 17 00:00:00 2001 From: tg Date: Thu, 13 Aug 2015 22:09:10 +0000 Subject: [PATCH 5/5] ; on OS/2 --- mksh.1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mksh.1 b/mksh.1 index 54c9602..5734081 100644 --- a/mksh.1 +++ b/mksh.1 @@ -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 $ .\"- .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, @@ -74,7 +74,7 @@ .\" with -mandoc, it might implement .Mx itself, but we want to .\" 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. .\" @@ -1946,8 +1946,8 @@ Assigning 1 to this parameter causes .Ic getopts to process arguments from the beginning the next time it is invoked. .It Ev PATH -A colon separated list of directories that are searched when looking for -commands and files sourced using the +A colon (semicolon on OS/2) separated list of directories that are +searched when looking for commands and files sourced using the .Sq \&. command (see below). An empty string resulting from a leading or trailing