* inittraps: convert signal _names_ to uppercase, we're matching

case-sensitively in the 'trap' builtin, and Mac OSX has them
  in lowercase at sys_signame[]…
* gettraps: optimise
This commit is contained in:
tg 2007-01-12 00:37:09 +00:00
parent 2f15a11c55
commit 0e4bbd4bf6

View File

@ -3,7 +3,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.35 2007/01/12 00:25:40 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.36 2007/01/12 00:37:09 tg Exp $");
Trap sigtraps[NSIG + 1]; Trap sigtraps[NSIG + 1];
static struct sigaction Sigact_ign, Sigact_trap; static struct sigaction Sigact_ign, Sigact_trap;
@ -960,7 +960,8 @@ sprinkle(int fd)
void void
inittraps(void) inittraps(void)
{ {
int i; int i;
char *s;
/* Populate sigtraps based on sys_signame and sys_siglist. */ /* Populate sigtraps based on sys_signame and sys_siglist. */
for (i = 0; i <= NSIG; i++) { for (i = 0; i <= NSIG; i++) {
@ -970,13 +971,23 @@ inittraps(void)
sigtraps[i].mess = "Error handler"; sigtraps[i].mess = "Error handler";
} else { } else {
#if HAVE_SYS_SIGNAME || HAVE_SYS_SIGNAME #if HAVE_SYS_SIGNAME || HAVE_SYS_SIGNAME
sigtraps[i].name = sys_signame[i]; s = sys_signame[i];
#else #else
const struct mksh_sigpair *pair = mksh_sigpairs; const struct mksh_sigpair *pair = mksh_sigpairs;
while ((pair->nr != i) && (pair->name != NULL)) while ((pair->nr != i) && (pair->name != NULL))
++pair; ++pair;
sigtraps[i].name = pair->name; s = pair->name;
#endif #endif
if ((s == NULL) ||
(s[0] == '\0'))
sigtraps[i].name = shf_smprintf("%d", i);
else {
sigtraps[i].name = s = str_save(
!strncasecmp(s, "SIG", 3) ? s + 3 : s,
APERM);
while (*s = ksh_toupper(*s))
++s;
}
#if HAVE_SYS_SIGLIST #if HAVE_SYS_SIGLIST
sigtraps[i].mess = sys_siglist[i]; sigtraps[i].mess = sys_siglist[i];
#elif HAVE__SYS_SIGLIST #elif HAVE__SYS_SIGLIST
@ -986,14 +997,9 @@ inittraps(void)
#else #else
sigtraps[i].mess = NULL; sigtraps[i].mess = NULL;
#endif #endif
if ((sigtraps[i].name == NULL) ||
(sigtraps[i].name[0] == '\0'))
sigtraps[i].name = shf_smprintf("%d", i);
if ((sigtraps[i].mess == NULL) || if ((sigtraps[i].mess == NULL) ||
(sigtraps[i].mess[0] == '\0')) (sigtraps[i].mess[0] == '\0'))
sigtraps[i].mess = shf_smprintf("Signal %d", i); sigtraps[i].mess = shf_smprintf("Signal %d", i);
if (!strncasecmp(sigtraps[i].name, "SIG", 3))
sigtraps[i].name += 3;
} }
} }
sigtraps[SIGEXIT_].name = "EXIT"; /* our name for signal 0 */ sigtraps[SIGEXIT_].name = "EXIT"; /* our name for signal 0 */
@ -1048,22 +1054,18 @@ alarm_catcher(int sig __attribute__((unused)))
Trap * Trap *
gettrap(const char *name, int igncase) gettrap(const char *name, int igncase)
{ {
int i; int n = NSIG + 1;
Trap *p; Trap *p;
if (ksh_isdigit(*name)) { if (ksh_isdigit(*name)) {
int n;
if (getn(name, &n) && 0 <= n && n < NSIG) if (getn(name, &n) && 0 <= n && n < NSIG)
return &sigtraps[n]; return (&sigtraps[n]);
return NULL; } else for (p = sigtraps; --n >= 0; p++)
}
for (p = sigtraps, i = NSIG+1; --i >= 0; p++)
if (!(igncase ? strcasecmp : strcmp)(p->name, name) || if (!(igncase ? strcasecmp : strcmp)(p->name, name) ||
(!strncasecmp(name, "SIG", 3) && (!strncasecmp(name, "SIG", 3) &&
!(igncase ? strcasecmp : strcmp)(p->name, name + 3))) !(igncase ? strcasecmp : strcmp)(p->name, name + 3)))
return (p); return (p);
return NULL; return (NULL);
} }
/* /*