diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-29 16:46:07 +0000 | 
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-29 16:46:07 +0000 | 
| commit | 7357e8836f7c742602f59cc8f2b97382634c59b8 (patch) | |
| tree | 0c8c736305cb1922b70cd99d4d8e5f80114653e8 /libc | |
| parent | 35ae1599438a15568818bf09b493d7b49039d452 (diff) | |
shring sugnal-relared stuff a bit. BTW why constant memset is not inlined by gcc?
    text           data     bss     dec     hex filename
-  38015          18096    8636   64747    fceb lib/libpthread-0.9.30-svn.so
+  38001          18096    8636   64733    fcdd lib/libpthread-0.9.30-svn.so
- 274842           1835   19012  295689   48309 lib/libuClibc-0.9.30-svn.so
+ 274779           1835   19012  295626   482ca lib/libuClibc-0.9.30-svn.so
Diffstat (limited to 'libc')
| -rw-r--r-- | libc/signal/sigblock.c | 6 | ||||
| -rw-r--r-- | libc/signal/sigignore.c | 6 | ||||
| -rw-r--r-- | libc/signal/signal.c | 5 | ||||
| -rw-r--r-- | libc/signal/sigpause.c | 9 | ||||
| -rw-r--r-- | libc/signal/sigset-cvt-mask.h | 18 | ||||
| -rw-r--r-- | libc/signal/sigset.c | 38 | ||||
| -rw-r--r-- | libc/signal/sigsetmask.c | 7 | ||||
| -rw-r--r-- | libc/signal/sigwait.c | 6 | ||||
| -rw-r--r-- | libc/signal/sysv_signal.c | 6 | ||||
| -rw-r--r-- | libc/stdlib/abort.c | 11 | ||||
| -rw-r--r-- | libc/sysdeps/linux/alpha/sigprocmask.c | 5 | ||||
| -rw-r--r-- | libc/sysdeps/linux/common/ssp.c | 7 | ||||
| -rw-r--r-- | libc/unistd/sleep.c | 16 | 
13 files changed, 59 insertions, 81 deletions
diff --git a/libc/signal/sigblock.c b/libc/signal/sigblock.c index 7051a94ce..72b42c45e 100644 --- a/libc/signal/sigblock.c +++ b/libc/signal/sigblock.c @@ -19,6 +19,7 @@  #define __UCLIBC_HIDE_DEPRECATED__  #include <errno.h>  #include <signal.h> +#include <string.h>  /* libc_hidden_proto(sigprocmask) */ @@ -30,12 +31,9 @@ int sigblock (int mask)  {    sigset_t set, oset; -  if (sigset_set_old_mask (&set, mask) < 0) -    return -1; - +  sigset_set_old_mask (&set, mask);    if (sigprocmask (SIG_BLOCK, &set, &oset) < 0)      return -1; -    return sigset_get_old_mask (&oset);  }  libc_hidden_def(sigblock) diff --git a/libc/signal/sigignore.c b/libc/signal/sigignore.c index 58d1c9bfd..9e658c6c6 100644 --- a/libc/signal/sigignore.c +++ b/libc/signal/sigignore.c @@ -30,10 +30,10 @@ int sigignore (int sig)  {    struct sigaction act; +  memset(&act, 0, sizeof(act)); +  /*__sigemptyset (&act.sa_mask);*/ +  /*act.sa_flags = 0;*/    act.sa_handler = SIG_IGN; -  if (__sigemptyset (&act.sa_mask) < 0) -    return -1; -  act.sa_flags = 0;    return sigaction (sig, &act, NULL);  } diff --git a/libc/signal/signal.c b/libc/signal/signal.c index 4d379606f..0ed281ab1 100644 --- a/libc/signal/signal.c +++ b/libc/signal/signal.c @@ -42,9 +42,8 @@ __bsd_signal (int sig, __sighandler_t handler)      }    act.sa_handler = handler; -  if (__sigemptyset (&act.sa_mask) < 0 -      || __sigaddset (&act.sa_mask, sig) < 0) -    return SIG_ERR; +  __sigemptyset (&act.sa_mask); +  __sigaddset (&act.sa_mask, sig);    act.sa_flags = __sigismember (&_sigintr, sig) ? 0 : SA_RESTART;    if (sigaction (sig, &act, &oact) < 0)      return SIG_ERR; diff --git a/libc/signal/sigpause.c b/libc/signal/sigpause.c index 195e88efc..96dd93368 100644 --- a/libc/signal/sigpause.c +++ b/libc/signal/sigpause.c @@ -23,6 +23,7 @@  #define __FAVOR_BSD  #include <signal.h>  #include <stddef.h>		/* For NULL.  */ +#include <string.h>  /* libc_hidden_proto(sigprocmask) */  /* libc_hidden_proto(sigdelset) */ @@ -37,16 +38,18 @@ int __sigpause (int sig_or_mask, int is_sig)  {    sigset_t set; -  if (is_sig != 0) +  if (is_sig)      { +//TODO: error check for sig_or_mask = BIGNUM? +        /* The modern X/Open implementation is requested.  */        if (sigprocmask (0, NULL, &set) < 0  	  /* Yes, we call `sigdelset' and not `__sigdelset'.  */  	  || sigdelset (&set, sig_or_mask) < 0)  	return -1;      } -  else if (sigset_set_old_mask (&set, sig_or_mask) < 0) -    return -1; +  else +    sigset_set_old_mask (&set, sig_or_mask);    return sigsuspend (&set);  } diff --git a/libc/signal/sigset-cvt-mask.h b/libc/signal/sigset-cvt-mask.h index 7b2f4cdce..83be40a51 100644 --- a/libc/signal/sigset-cvt-mask.h +++ b/libc/signal/sigset-cvt-mask.h @@ -19,22 +19,12 @@     Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA     02111-1307 USA.  */ -static __inline__ int __attribute__ ((unused)) +static __inline__ void __attribute__ ((unused))  sigset_set_old_mask (sigset_t *set, int mask)  { -  unsigned long int *ptr; -  int cnt; - -  ptr = &set->__val[0]; - -  *ptr++ = (unsigned int) mask; - -  cnt = _SIGSET_NWORDS - 2; -  do -    *ptr++ = 0ul; -  while (--cnt >= 0); - -  return 0; +  if (_SIGSET_NWORDS > 1) +    memset(set, 0, sizeof(*set)); +  set->__val[0] = (unsigned int) mask;  }  static __inline__ int __attribute__ ((unused)) diff --git a/libc/signal/sigset.c b/libc/signal/sigset.c index f4c04dc3e..3efbf3ea3 100644 --- a/libc/signal/sigset.c +++ b/libc/signal/sigset.c @@ -31,17 +31,20 @@ __sighandler_t sigset (int sig, __sighandler_t disp)    struct sigaction act, oact;    sigset_t set; +  /* Check signal extents to protect __sigismember.  */ +  if (disp == SIG_ERR || sig < 1 || sig >= NSIG) +    { +      __set_errno (EINVAL); +      return SIG_ERR; +    } +  #ifdef SIG_HOLD    /* Handle SIG_HOLD first.  */    if (disp == SIG_HOLD)      {        /* Create an empty signal set.  */ -      if (__sigemptyset (&set) < 0) -	return SIG_ERR; - -      /* Add the specified signal.  */ -      if (__sigaddset (&set, sig) < 0) -	return SIG_ERR; +      __sigemptyset (&set); +      __sigaddset (&set, sig);        /* Add the signal set to the current signal mask.  */        if (sigprocmask (SIG_BLOCK, &set, NULL) < 0) @@ -51,27 +54,16 @@ __sighandler_t sigset (int sig, __sighandler_t disp)      }  #endif	/* SIG_HOLD */ -  /* Check signal extents to protect __sigismember.  */ -  if (disp == SIG_ERR || sig < 1 || sig >= NSIG) -    { -      __set_errno (EINVAL); -      return SIG_ERR; -    } - +  memset(&act, 0, sizeof(act)); +  //__sigemptyset (&act.sa_mask); +  //act.sa_flags = 0;    act.sa_handler = disp; -  if (__sigemptyset (&act.sa_mask) < 0) -    return SIG_ERR; -  act.sa_flags = 0;    if (sigaction (sig, &act, &oact) < 0)      return SIG_ERR; -  /* Create an empty signal set.  */ -  if (__sigemptyset (&set) < 0) -    return SIG_ERR; - -  /* Add the specified signal.  */ -  if (__sigaddset (&set, sig) < 0) -    return SIG_ERR; +  /* Create an empty signal set. Add the specified signal.  */ +  __sigemptyset (&set); +  __sigaddset (&set, sig);    /* Remove the signal set from the current signal mask.  */    if (sigprocmask (SIG_UNBLOCK, &set, NULL) < 0) diff --git a/libc/signal/sigsetmask.c b/libc/signal/sigsetmask.c index 5de4b59e4..9349deb38 100644 --- a/libc/signal/sigsetmask.c +++ b/libc/signal/sigsetmask.c @@ -19,6 +19,7 @@  #define __UCLIBC_HIDE_DEPRECATED__  #include <errno.h>  #include <signal.h> +#include <string.h>  /* libc_hidden_proto(sigprocmask) */ @@ -31,13 +32,9 @@ sigsetmask (int mask)  {    sigset_t set, oset; -  if (sigset_set_old_mask (&set, mask) < 0) -    return -1; - +  sigset_set_old_mask (&set, mask);    if (sigprocmask (SIG_SETMASK, &set, &oset) < 0)      return -1; - -    return sigset_get_old_mask (&oset);  }  libc_hidden_def(sigsetmask) diff --git a/libc/signal/sigwait.c b/libc/signal/sigwait.c index c902ee888..9b2c32079 100644 --- a/libc/signal/sigwait.c +++ b/libc/signal/sigwait.c @@ -28,8 +28,8 @@  int __sigwait (const sigset_t *set, int *sig) attribute_hidden;  int __sigwait (const sigset_t *set, int *sig)  { -	int ret = 1; -	if ((ret = sigwaitinfo(set, NULL)) != -1) { +	int ret = sigwaitinfo(set, NULL); +	if (ret != -1) {  		*sig = ret;  		return 0;  	} @@ -41,7 +41,7 @@ int __sigwait (const sigset_t *set, int *sig)  /* libc_hidden_proto(sigaction) */  /* libc_hidden_proto(sigsuspend) */ -static int was_sig; /* obviously not thread-safe */ +static smallint was_sig; /* obviously not thread-safe */  static void ignore_signal(int sig)  {  	was_sig = sig; diff --git a/libc/signal/sysv_signal.c b/libc/signal/sysv_signal.c index c0cd19a95..f573482f9 100644 --- a/libc/signal/sysv_signal.c +++ b/libc/signal/sysv_signal.c @@ -47,10 +47,8 @@ __sighandler_t __sysv_signal (int sig, __sighandler_t handler)      }    act.sa_handler = handler; -  if (__sigemptyset (&act.sa_mask) < 0) -    return SIG_ERR; -  act.sa_flags = SA_ONESHOT | SA_NOMASK | SA_INTERRUPT; -  act.sa_flags &= ~SA_RESTART; +  __sigemptyset (&act.sa_mask); +  act.sa_flags = (SA_ONESHOT | SA_NOMASK | SA_INTERRUPT) & ~SA_RESTART;    if (sigaction (sig, &act, &oact) < 0)      return SIG_ERR; diff --git a/libc/stdlib/abort.c b/libc/stdlib/abort.c index 7291d0ea4..901218f8d 100644 --- a/libc/stdlib/abort.c +++ b/libc/stdlib/abort.c @@ -60,9 +60,9 @@ void abort(void)  	__UCLIBC_MUTEX_LOCK_CANCEL_UNSAFE(mylock);  	/* Unmask SIGABRT to be sure we can get it */ -	if (__sigemptyset(&sigs) == 0 && __sigaddset(&sigs, SIGABRT) == 0) { -		sigprocmask(SIG_UNBLOCK, &sigs, (sigset_t *) NULL); -	} +	__sigemptyset(&sigs); +	__sigaddset(&sigs, SIGABRT); +	sigprocmask(SIG_UNBLOCK, &sigs, (sigset_t *) NULL);  	while (1) {  		/* Try to suicide with a SIGABRT */ @@ -91,9 +91,10 @@ abort_it:  			been_there_done_that++;  			memset(&act, '\0', sizeof(struct sigaction)); -			act.sa_handler = SIG_DFL; +			if (SIG_DFL) /* if it's constant zero, already done */ +				act.sa_handler = SIG_DFL;  			__sigfillset(&act.sa_mask); -			act.sa_flags = 0; +			/*act.sa_flags = 0; - memset did it */  			sigaction(SIGABRT, &act, NULL);  			goto abort_it; diff --git a/libc/sysdeps/linux/alpha/sigprocmask.c b/libc/sysdeps/linux/alpha/sigprocmask.c index f5e3c8d91..5728418b5 100644 --- a/libc/sysdeps/linux/alpha/sigprocmask.c +++ b/libc/sysdeps/linux/alpha/sigprocmask.c @@ -51,10 +51,9 @@ sigprocmask (int how, const sigset_t *set, sigset_t *oset)    if (oset)      { +      if (_SIGSET_NWORDS > 1) +        memset(oset, 0, sizeof(*oset));        oset->__val[0] = result; -      result = _SIGSET_NWORDS; -      while (--result > 0) -	oset->__val[result] = 0;      }    return 0;  } diff --git a/libc/sysdeps/linux/common/ssp.c b/libc/sysdeps/linux/common/ssp.c index 73d7113b8..c244c6220 100644 --- a/libc/sysdeps/linux/common/ssp.c +++ b/libc/sysdeps/linux/common/ssp.c @@ -57,10 +57,11 @@ static void block_signals(void)  	sigprocmask(SIG_BLOCK, &mask, NULL);	/* except SSP_SIGTYPE */  	/* Make the default handler associated with the signal handler */ -	memset(&sa, 0, sizeof(struct sigaction)); +	memset(&sa, 0, sizeof(sa));  	sigfillset(&sa.sa_mask);	/* Block all signals */ -	sa.sa_flags = 0; -	sa.sa_handler = SIG_DFL; +	/* sa.sa_flags = 0; - memset did it */ +	if (SIG_DFL) /* if it's constant zero, it's already done */ +		sa.sa_handler = SIG_DFL;  	sigaction(SSP_SIGTYPE, &sa, NULL);  } diff --git a/libc/unistd/sleep.c b/libc/unistd/sleep.c index e7152c46b..8cac306ce 100644 --- a/libc/unistd/sleep.c +++ b/libc/unistd/sleep.c @@ -66,9 +66,9 @@ unsigned int sleep (unsigned int seconds)      /* Linux will wake up the system call, nanosleep, when SIGCHLD         arrives even if SIGCHLD is ignored.  We have to deal with it         in libc.  We block SIGCHLD first.  */ -    if (__sigemptyset (&set) < 0 -	    || __sigaddset (&set, SIGCHLD) < 0 -	    || sigprocmask (SIG_BLOCK, &set, &oset)) +    __sigemptyset (&set); +    __sigaddset (&set, SIGCHLD); +    if (sigprocmask (SIG_BLOCK, &set, &oset))  	return -1;      /* If SIGCHLD is already blocked, we don't have to do anything.  */ @@ -77,8 +77,8 @@ unsigned int sleep (unsigned int seconds)  	int saved_errno;  	struct sigaction oact; -	if (__sigemptyset (&set) < 0 || __sigaddset (&set, SIGCHLD) < 0) -	    return -1; +	__sigemptyset (&set); +	__sigaddset (&set, SIGCHLD);  	/* We get the signal handler for SIGCHLD.  */  	if (sigaction (SIGCHLD, (struct sigaction *) NULL, &oact) < 0) @@ -136,9 +136,9 @@ unsigned int sleep (unsigned int seconds)  	return 0;      /* block SIGALRM */ -    if (__sigemptyset (&set) < 0 -	    || __sigaddset (&set, SIGALRM) < 0 -	    || sigprocmask (SIG_BLOCK, &set, &oset)) +    __sigemptyset (&set); +    __sigaddset (&set, SIGALRM); +    if (sigprocmask (SIG_BLOCK, &set, &oset))  	return seconds;      act.sa_handler = sleep_alarm_handler;  | 
