From c51e067e62e4c4f72461eb1c07dd263a457ed2a2 Mon Sep 17 00:00:00 2001 From: tg Date: Thu, 14 Jan 2016 23:18:11 +0000 Subject: [PATCH] incorporate more feedback from schily --- histrap.c | 6 +++--- jobs.c | 11 ++++------- mksh.1 | 11 ++++++++--- sh.h | 6 ++++-- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/histrap.c b/histrap.c index eae9e9d..57f2124 100644 --- a/histrap.c +++ b/histrap.c @@ -3,7 +3,7 @@ /*- * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, - * 2011, 2012, 2014, 2015 + * 2011, 2012, 2014, 2015, 2016 * mirabilos * * Provided that these terms and disclaimer and all copyright notices @@ -27,7 +27,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.151 2015/11/29 17:05:01 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.152 2016/01/14 23:18:08 tg Exp $"); Trap sigtraps[ksh_NSIG + 1]; static struct sigaction Sigact_ign; @@ -1213,7 +1213,7 @@ fatal_trap_check(void) do { if (p->set && (p->flags & (TF_DFL_INTR|TF_FATAL))) /* return value is used as an exit code */ - return (128 + p->signal); + return (ksh_sigmask(p->signal)); ++p; } while (--i); return (0); diff --git a/jobs.c b/jobs.c index 0e355a9..0cecdc5 100644 --- a/jobs.c +++ b/jobs.c @@ -2,7 +2,7 @@ /*- * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011, - * 2012, 2013, 2014, 2015 + * 2012, 2013, 2014, 2015, 2016 * mirabilos * * Provided that these terms and disclaimer and all copyright notices @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.116 2015/10/09 16:11:15 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.117 2016/01/14 23:18:09 tg Exp $"); #if HAVE_KILLPG #define mksh_killpg killpg @@ -215,14 +215,11 @@ j_init(void) static int proc_errorlevel(Proc *p) { - int termsig; - switch (p->state) { case PEXITED: return ((WEXITSTATUS(p->status)) & 255); case PSIGNALLED: - termsig = WTERMSIG(p->status); - return ((termsig < 1 || termsig > 127) ? 255 : 128 + termsig); + return (ksh_sigmask(WTERMSIG(p->status))); default: return (0); } @@ -756,7 +753,7 @@ waitfor(const char *cp, int *sigp) if (rv < 0) /* we were interrupted */ - *sigp = 128 + -rv; + *sigp = ksh_sigmask(-rv); return (rv); } diff --git a/mksh.1 b/mksh.1 index 72da56d..4e056e4 100644 --- a/mksh.1 +++ b/mksh.1 @@ -1,4 +1,4 @@ -.\" $MirOS: src/bin/mksh/mksh.1,v 1.386 2016/01/13 17:20:50 tg Exp $ +.\" $MirOS: src/bin/mksh/mksh.1,v 1.387 2016/01/14 23:18:09 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: January 13 2016 $ +.Dd $Mdocdate: January 14 2016 $ .\" .\" Check which macro package we use, and do other -mdoc setup. .\" @@ -179,6 +179,11 @@ script use. Its command language is a superset of the .Xr sh C shell language and largely compatible to the original Korn shell. +At times, this manual page may give scripting advice; while it +sometimes does take portable shell scripting or various standards +into account all information is first and foremost presented with +.Nm +in mind and should be taken as such. .Ss I'm an Android user, so what's mksh? .Nm mksh is a @@ -1744,7 +1749,7 @@ command below for a list of options). The exit status of the last non-asynchronous command executed. If the last command was killed by a signal, .Ic $?\& -is set to 128 plus the signal number. +is set to 128 plus the signal number, but at most 255. .It Ev 0 The name of the shell, determined as follows: the first argument to diff --git a/sh.h b/sh.h index 1fb56ca..109596c 100644 --- a/sh.h +++ b/sh.h @@ -175,9 +175,9 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.754 2016/01/14 22:49:32 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.755 2016/01/14 23:18:11 tg Exp $"); #endif -#define MKSH_VERSION "R52 2016/01/13" +#define MKSH_VERSION "R52 2016/01/14" /* arithmetic types: C implementation */ #if !HAVE_CAN_INTTYPES @@ -379,6 +379,8 @@ struct rusage { #define ksh_NSIG 64 #endif +#define ksh_sigmask(sig) (((sig) < 1 || (sig) > 127) ? 255 : 128 + (sig)) + /* OS-dependent additions (functions, variables, by OS) */