fix _NSIG usage
This commit is contained in:
		
							parent
							
								
									c6cce1823d
								
							
						
					
					
						commit
						6da61b8f05
					
				@ -854,7 +854,7 @@ register struct op *t;
 | 
			
		||||
	register int  resetsig;
 | 
			
		||||
 | 
			
		||||
	if (t->words[1] == NULL) {
 | 
			
		||||
		for (i=0; i<=_NSIG; i++)
 | 
			
		||||
		for (i=0; i<_NSIG; i++)
 | 
			
		||||
			if (trap[i]) {
 | 
			
		||||
				prn(i);
 | 
			
		||||
				prs(": ");
 | 
			
		||||
@ -894,7 +894,7 @@ char *s;
 | 
			
		||||
{
 | 
			
		||||
	register int n;
 | 
			
		||||
 | 
			
		||||
	if ((n = getn(s)) < 0 || n > _NSIG) {
 | 
			
		||||
	if ((n = getn(s)) < 0 || n >= _NSIG) {
 | 
			
		||||
		err("trap: bad signal number");
 | 
			
		||||
		n = 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -387,7 +387,7 @@ int quoted;
 | 
			
		||||
	}
 | 
			
		||||
	*e.linep = 0;
 | 
			
		||||
	/* allow trapped signals */
 | 
			
		||||
	for (i=0; i<=_NSIG; i++)
 | 
			
		||||
	for (i=0; i<_NSIG; i++)
 | 
			
		||||
		if (ourtrap[i] && signal(i, SIG_IGN) != SIG_IGN)
 | 
			
		||||
			signal(i, SIG_DFL);
 | 
			
		||||
	dup2(pf[1], 1);
 | 
			
		||||
 | 
			
		||||
@ -69,7 +69,7 @@ char **argv;
 | 
			
		||||
	}
 | 
			
		||||
	if (sig < 0) {						/* numeric? */
 | 
			
		||||
		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;
 | 
			
		||||
	}
 | 
			
		||||
	argv++;
 | 
			
		||||
 | 
			
		||||
@ -445,7 +445,7 @@ char *argv[];
 | 
			
		||||
 | 
			
		||||
	/* Reset signals to default values. */
 | 
			
		||||
	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. */
 | 
			
		||||
	execve(sh, argx, env);
 | 
			
		||||
 | 
			
		||||
@ -336,7 +336,7 @@ PUBLIC void send_sig(int proc_nr, int sig_nr)
 | 
			
		||||
 *===========================================================================*/
 | 
			
		||||
PUBLIC void cause_sig(proc_nr, sig_nr)
 | 
			
		||||
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:
 | 
			
		||||
 *  - HARDWARE wanting to cause a SIGSEGV after a CPU exception
 | 
			
		||||
 | 
			
		||||
@ -32,7 +32,7 @@ message *m_ptr;			/* pointer to request message */
 | 
			
		||||
  proc_nr_e= m_ptr->SIG_ENDPT;
 | 
			
		||||
 | 
			
		||||
  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);
 | 
			
		||||
 | 
			
		||||
  /* Set pending signal to be processed by the PM. */
 | 
			
		||||
 | 
			
		||||
@ -15,7 +15,7 @@ pid_t _getpid(void);
 | 
			
		||||
int
 | 
			
		||||
raise(int sig)
 | 
			
		||||
{
 | 
			
		||||
	if (sig < 0 || sig > _NSIG)
 | 
			
		||||
	if (sig < 0 || sig >= _NSIG)
 | 
			
		||||
		return -1;
 | 
			
		||||
	return _kill(_getpid(), sig);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -11,7 +11,7 @@ sighandler_t disp;		/* signal handler, or SIG_DFL, or SIG_IGN */
 | 
			
		||||
{
 | 
			
		||||
  struct sigaction sa, osa;
 | 
			
		||||
 | 
			
		||||
  if (sig <= 0 || sig > _NSIG || sig == SIGKILL) {
 | 
			
		||||
  if (sig <= 0 || sig >= _NSIG || sig == SIGKILL) {
 | 
			
		||||
	errno = EINVAL;
 | 
			
		||||
	return(SIG_ERR);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -2,6 +2,8 @@
 | 
			
		||||
/* System processes use simpler macros with no range error checking (defined in
 | 
			
		||||
 * signal.h). The ANSI signal() implementation now also uses the macro
 | 
			
		||||
 * 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 sigdelset	_sigdelset
 | 
			
		||||
@ -13,10 +15,10 @@
 | 
			
		||||
/* Low bit of signal masks. */
 | 
			
		||||
#define SIGBIT_0	((sigset_t) 1)
 | 
			
		||||
 | 
			
		||||
/* Mask of valid signals (0 - _NSIG). */
 | 
			
		||||
#define SIGMASK		(((SIGBIT_0 << _NSIG) << 1) - 1)
 | 
			
		||||
/* Mask of valid signals (0 - (_NSIG-1)). */
 | 
			
		||||
#define SIGMASK		((SIGBIT_0 << _NSIG) - 1)
 | 
			
		||||
 | 
			
		||||
#define sigisvalid(signo) ((unsigned) (signo) <= _NSIG)
 | 
			
		||||
#define sigisvalid(signo) ((unsigned) (signo) < _NSIG)
 | 
			
		||||
 | 
			
		||||
PUBLIC int sigaddset(set, signo)
 | 
			
		||||
sigset_t *set;
 | 
			
		||||
 | 
			
		||||
@ -238,10 +238,8 @@ void test37b()
 | 
			
		||||
  if (sigdelset(&s_nokill, SIGKILL) != 0) e(8);
 | 
			
		||||
  s_nokill_stop = s_nokill;
 | 
			
		||||
  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 && sigdelset(&s_nokill, SIGSTOP) != 0) e(888);
 | 
			
		||||
#endif /* _MINIX */
 | 
			
		||||
  if (SIGSTOP >= _NSIG) e(666);
 | 
			
		||||
  if (SIGSTOP < _NSIG && sigdelset(&s_nokill, SIGSTOP) != 0) e(888);
 | 
			
		||||
 | 
			
		||||
  /* 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.
 | 
			
		||||
@ -427,7 +425,7 @@ void test37c()
 | 
			
		||||
  if (signal(SIGINT, catch1) != SIG_DFL) e(11);
 | 
			
		||||
 | 
			
		||||
  /* 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(-1, SIG_DFL) != SIG_ERR) e(14);
 | 
			
		||||
 | 
			
		||||
@ -987,8 +985,8 @@ void clearsigstate()
 | 
			
		||||
  sigset_t sigset_var;
 | 
			
		||||
 | 
			
		||||
  /* Clear the signal state. */
 | 
			
		||||
  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_IGN);
 | 
			
		||||
  for (i = 1; i < _NSIG; i++) signal(i, SIG_DFL);
 | 
			
		||||
  sigfillset(&sigset_var);
 | 
			
		||||
  sigprocmask(SIG_UNBLOCK, &sigset_var, (sigset_t *)NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user