From f158d4d0dfebd2ac486c0e9c71986ae1cc937c86 Mon Sep 17 00:00:00 2001 From: tg Date: Mon, 23 May 2005 12:01:09 +0000 Subject: [PATCH] support getting sys_siglist[], sys_signame[] and NSIG retrieval for portable mksh on various operating systems --- gensigs.sh | 11 +++++++++++ histrap.c | 47 +++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 gensigs.sh diff --git a/gensigs.sh b/gensigs.sh new file mode 100644 index 0000000..fcd9e5a --- /dev/null +++ b/gensigs.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# $MirOS: src/bin/mksh/gensigs.sh,v 1.1 2005/05/23 12:01:09 tg Exp $ + +echo '#include ' | $CC -E -dD -D_ANSI_SOURCE - \ + | grep '[ ]SIG[A-Z0-9]*[ ]' \ + | sed 's/^\(.*[ ]SIG\)\([A-Z0-9]*\)\([ ].*\)$/\2/' \ + | while read name; do + ( echo '#include '; echo "__mksh_test: SIG$name" ) \ + | $CC -E - | fgrep __mksh_test: \ + | sed 's/^__mksh_test: \([0-9]*\).*$/ { \1, "'$name'" },/' +done | fgrep -v '{ ,' >signames.inc diff --git a/histrap.c b/histrap.c index 1f661e1..0fde320 100644 --- a/histrap.c +++ b/histrap.c @@ -1,13 +1,14 @@ -/** $MirOS: src/bin/mksh/histrap.c,v 1.1 2005/05/23 03:06:07 tg Exp $ */ +/** $MirOS: src/bin/mksh/histrap.c,v 1.2 2005/05/23 12:01:09 tg Exp $ */ /* $OpenBSD: history.c,v 1.30 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: trap.c,v 1.22 2005/03/30 17:16:37 deraadt Exp $ */ #include "sh.h" +#include /* for BSD */ #include #include #include -__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.1 2005/05/23 03:06:07 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.2 2005/05/23 12:01:09 tg Exp $"); static int histfd; static int hsize; @@ -32,6 +33,20 @@ static char *hname; /* current name of history file */ static int hstarted; /* set after hist_init() called */ static Source *hist_source; +#if defined(BSD) || defined(__APPLE__) +#define mksh_signame(x) sys_signame[(x)] +#define mksh_siglist(x) sys_siglist[(x)] +#elif defined(__INTERIX) +#define mksh_signame(x) __sys_signame[(x)] +#define mksh_siglist(x) __sys_siglist[(x)] +#define NSIG __sys_nsig +#elif defined(__gnu_linux__) || defined(__sun__) +#define NEED_MKSH_SIGNAME +#define mksh_siglist(x) strerror(x) +#else +# error "Define sys_sig{name,list} for this platform!" +#endif + Trap sigtraps[NSIG + 1]; static struct sigaction Sigact_ign, Sigact_trap; @@ -952,6 +967,30 @@ sprinkle(int fd) return(write(fd, mag, 2) != 2); } +#ifdef NEED_MKSH_SIGNAME + +struct _mksh_sigpair { + int nr; + const char *name; +} mksh_sigpair[] = { +#include "signames.inc" + { 0, NULL } +}; + +static const char * const +mksh_signame(int s) +{ + int i = 0; + + while (mksh_sigpair[i].name != NULL) { + if (mksh_sigpair[i].nr == s) + return mksh_sigpair[i].name; + ++i; + } + return NULL; +} +#endif + void inittraps(void) { @@ -964,8 +1003,8 @@ inittraps(void) sigtraps[i].name = "ERR"; sigtraps[i].mess = "Error handler"; } else { - sigtraps[i].name = sys_signame[i]; - sigtraps[i].mess = sys_siglist[i]; + sigtraps[i].name = mksh_signame(i); + sigtraps[i].mess = mksh_siglist(i); } } sigtraps[SIGEXIT_].name = "EXIT"; /* our name for signal 0 */