support getting sys_siglist[], sys_signame[] and NSIG retrieval

for portable mksh on various operating systems
This commit is contained in:
tg 2005-05-23 12:01:09 +00:00
parent 7af5be731b
commit f158d4d0df
2 changed files with 54 additions and 4 deletions

11
gensigs.sh Normal file
View File

@ -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 <signal.h>' | $CC -E -dD -D_ANSI_SOURCE - \
| grep '[ ]SIG[A-Z0-9]*[ ]' \
| sed 's/^\(.*[ ]SIG\)\([A-Z0-9]*\)\([ ].*\)$/\2/' \
| while read name; do
( echo '#include <signal.h>'; echo "__mksh_test: SIG$name" ) \
| $CC -E - | fgrep __mksh_test: \
| sed 's/^__mksh_test: \([0-9]*\).*$/ { \1, "'$name'" },/'
done | fgrep -v '{ ,' >signames.inc

View File

@ -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: 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 $ */ /* $OpenBSD: trap.c,v 1.22 2005/03/30 17:16:37 deraadt Exp $ */
#include "sh.h" #include "sh.h"
#include <sys/param.h> /* for BSD */
#include <sys/file.h> #include <sys/file.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/stat.h> #include <sys/stat.h>
__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 histfd;
static int hsize; static int hsize;
@ -32,6 +33,20 @@ static char *hname; /* current name of history file */
static int hstarted; /* set after hist_init() called */ static int hstarted; /* set after hist_init() called */
static Source *hist_source; 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]; Trap sigtraps[NSIG + 1];
static struct sigaction Sigact_ign, Sigact_trap; static struct sigaction Sigact_ign, Sigact_trap;
@ -952,6 +967,30 @@ sprinkle(int fd)
return(write(fd, mag, 2) != 2); 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 void
inittraps(void) inittraps(void)
{ {
@ -964,8 +1003,8 @@ inittraps(void)
sigtraps[i].name = "ERR"; sigtraps[i].name = "ERR";
sigtraps[i].mess = "Error handler"; sigtraps[i].mess = "Error handler";
} else { } else {
sigtraps[i].name = sys_signame[i]; sigtraps[i].name = mksh_signame(i);
sigtraps[i].mess = sys_siglist[i]; sigtraps[i].mess = mksh_siglist(i);
} }
} }
sigtraps[SIGEXIT_].name = "EXIT"; /* our name for signal 0 */ sigtraps[SIGEXIT_].name = "EXIT"; /* our name for signal 0 */