fix _NSIG usage

This commit is contained in:
David van Moolenbroek 2009-11-28 13:20:50 +00:00
parent c6cce1823d
commit 6da61b8f05
10 changed files with 19 additions and 19 deletions

View file

@ -854,7 +854,7 @@ register struct op *t;
register int resetsig; register int resetsig;
if (t->words[1] == NULL) { if (t->words[1] == NULL) {
for (i=0; i<=_NSIG; i++) for (i=0; i<_NSIG; i++)
if (trap[i]) { if (trap[i]) {
prn(i); prn(i);
prs(": "); prs(": ");
@ -894,7 +894,7 @@ char *s;
{ {
register int n; register int n;
if ((n = getn(s)) < 0 || n > _NSIG) { if ((n = getn(s)) < 0 || n >= _NSIG) {
err("trap: bad signal number"); err("trap: bad signal number");
n = 0; n = 0;
} }

View file

@ -387,7 +387,7 @@ int quoted;
} }
*e.linep = 0; *e.linep = 0;
/* allow trapped signals */ /* allow trapped signals */
for (i=0; i<=_NSIG; i++) for (i=0; i<_NSIG; i++)
if (ourtrap[i] && signal(i, SIG_IGN) != SIG_IGN) if (ourtrap[i] && signal(i, SIG_IGN) != SIG_IGN)
signal(i, SIG_DFL); signal(i, SIG_DFL);
dup2(pf[1], 1); dup2(pf[1], 1);

View file

@ -69,7 +69,7 @@ char **argv;
} }
if (sig < 0) { /* numeric? */ if (sig < 0) { /* numeric? */
ul = strtoul(argv[1] + 1, &end, 10); ul = strtoul(argv[1] + 1, &end, 10);
if (end == argv[1] + 1 || *end != 0 || ul > _NSIG) usage(); if (end == argv[1] + 1 || *end != 0 || ul >= _NSIG) usage();
sig = ul; sig = ul;
} }
argv++; argv++;

View file

@ -445,7 +445,7 @@ char *argv[];
/* Reset signals to default values. */ /* Reset signals to default values. */
sa.sa_handler = SIG_DFL; sa.sa_handler = SIG_DFL;
for (n = 1; n <= _NSIG; ++n) sigaction(n, &sa, NULL); for (n = 1; n < _NSIG; ++n) sigaction(n, &sa, NULL);
/* Execute the user's shell. */ /* Execute the user's shell. */
execve(sh, argx, env); execve(sh, argx, env);

View file

@ -336,7 +336,7 @@ PUBLIC void send_sig(int proc_nr, int sig_nr)
*===========================================================================*/ *===========================================================================*/
PUBLIC void cause_sig(proc_nr, sig_nr) PUBLIC void cause_sig(proc_nr, sig_nr)
int proc_nr; /* process to be signalled */ int proc_nr; /* process to be signalled */
int sig_nr; /* signal to be sent, 1 to _NSIG */ int sig_nr; /* signal to be sent */
{ {
/* A system process wants to send a signal to a process. Examples are: /* A system process wants to send a signal to a process. Examples are:
* - HARDWARE wanting to cause a SIGSEGV after a CPU exception * - HARDWARE wanting to cause a SIGSEGV after a CPU exception

View file

@ -32,7 +32,7 @@ message *m_ptr; /* pointer to request message */
proc_nr_e= m_ptr->SIG_ENDPT; proc_nr_e= m_ptr->SIG_ENDPT;
if (!isokendpt(proc_nr_e, &proc_nr)) return(EINVAL); if (!isokendpt(proc_nr_e, &proc_nr)) return(EINVAL);
if (sig_nr > _NSIG) return(EINVAL); if (sig_nr >= _NSIG) return(EINVAL);
if (iskerneln(proc_nr)) return(EPERM); if (iskerneln(proc_nr)) return(EPERM);
/* Set pending signal to be processed by the PM. */ /* Set pending signal to be processed by the PM. */

View file

@ -15,7 +15,7 @@ pid_t _getpid(void);
int int
raise(int sig) raise(int sig)
{ {
if (sig < 0 || sig > _NSIG) if (sig < 0 || sig >= _NSIG)
return -1; return -1;
return _kill(_getpid(), sig); return _kill(_getpid(), sig);
} }

View file

@ -11,7 +11,7 @@ sighandler_t disp; /* signal handler, or SIG_DFL, or SIG_IGN */
{ {
struct sigaction sa, osa; struct sigaction sa, osa;
if (sig <= 0 || sig > _NSIG || sig == SIGKILL) { if (sig <= 0 || sig >= _NSIG || sig == SIGKILL) {
errno = EINVAL; errno = EINVAL;
return(SIG_ERR); return(SIG_ERR);
} }

View file

@ -2,6 +2,8 @@
/* System processes use simpler macros with no range error checking (defined in /* System processes use simpler macros with no range error checking (defined in
* signal.h). The ANSI signal() implementation now also uses the macro * signal.h). The ANSI signal() implementation now also uses the macro
* versions, which makes hiding of the functions here a historical remains. * versions, which makes hiding of the functions here a historical remains.
*
* _NSIG is supposed to be the highest signal number plus one.
*/ */
#define sigaddset _sigaddset #define sigaddset _sigaddset
#define sigdelset _sigdelset #define sigdelset _sigdelset
@ -13,10 +15,10 @@
/* Low bit of signal masks. */ /* Low bit of signal masks. */
#define SIGBIT_0 ((sigset_t) 1) #define SIGBIT_0 ((sigset_t) 1)
/* Mask of valid signals (0 - _NSIG). */ /* Mask of valid signals (0 - (_NSIG-1)). */
#define SIGMASK (((SIGBIT_0 << _NSIG) << 1) - 1) #define SIGMASK ((SIGBIT_0 << _NSIG) - 1)
#define sigisvalid(signo) ((unsigned) (signo) <= _NSIG) #define sigisvalid(signo) ((unsigned) (signo) < _NSIG)
PUBLIC int sigaddset(set, signo) PUBLIC int sigaddset(set, signo)
sigset_t *set; sigset_t *set;

View file

@ -238,10 +238,8 @@ void test37b()
if (sigdelset(&s_nokill, SIGKILL) != 0) e(8); if (sigdelset(&s_nokill, SIGKILL) != 0) e(8);
s_nokill_stop = s_nokill; s_nokill_stop = s_nokill;
if (sigdelset(&s_nokill_stop, SIGSTOP) != 0) e(8); if (sigdelset(&s_nokill_stop, SIGSTOP) != 0) e(8);
#ifndef _MINIX /* XXX - should unsupported signals be <= _NSIG? */ if (SIGSTOP >= _NSIG) e(666);
if (SIGSTOP > _NSIG) e(666); if (SIGSTOP < _NSIG && sigdelset(&s_nokill, SIGSTOP) != 0) e(888);
if (SIGSTOP <= _NSIG && sigdelset(&s_nokill, SIGSTOP) != 0) e(888);
#endif /* _MINIX */
/* Now get most of the signals into default state. Don't change SIGINT /* Now get most of the signals into default state. Don't change SIGINT
* or SIGQUIT, so this program can be killed. SIGKILL is also special. * or SIGQUIT, so this program can be killed. SIGKILL is also special.
@ -427,7 +425,7 @@ void test37c()
if (signal(SIGINT, catch1) != SIG_DFL) e(11); if (signal(SIGINT, catch1) != SIG_DFL) e(11);
/* Verify that SIG_ERR is correctly generated. */ /* Verify that SIG_ERR is correctly generated. */
if (signal(_NSIG + 1, catch1) != SIG_ERR) e(12); if (signal(_NSIG, catch1) != SIG_ERR) e(12);
if (signal(0, catch1) != SIG_ERR) e(13); if (signal(0, catch1) != SIG_ERR) e(13);
if (signal(-1, SIG_DFL) != SIG_ERR) e(14); if (signal(-1, SIG_DFL) != SIG_ERR) e(14);
@ -987,8 +985,8 @@ void clearsigstate()
sigset_t sigset_var; sigset_t sigset_var;
/* Clear the signal state. */ /* Clear the signal state. */
for (i = 1; i <= _NSIG; i++) signal(i, SIG_IGN); for (i = 1; i < _NSIG; i++) signal(i, SIG_IGN);
for (i = 1; i <= _NSIG; i++) signal(i, SIG_DFL); for (i = 1; i < _NSIG; i++) signal(i, SIG_DFL);
sigfillset(&sigset_var); sigfillset(&sigset_var);
sigprocmask(SIG_UNBLOCK, &sigset_var, (sigset_t *)NULL); sigprocmask(SIG_UNBLOCK, &sigset_var, (sigset_t *)NULL);
} }