Browse Source

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
Denis Vlasenko 16 years ago
parent
commit
7357e8836f

+ 2 - 4
libc/signal/sigblock.c

@@ -19,6 +19,7 @@
 #define __UCLIBC_HIDE_DEPRECATED__
 #define __UCLIBC_HIDE_DEPRECATED__
 #include <errno.h>
 #include <errno.h>
 #include <signal.h>
 #include <signal.h>
+#include <string.h>
 
 
 /* libc_hidden_proto(sigprocmask) */
 /* libc_hidden_proto(sigprocmask) */
 
 
@@ -30,12 +31,9 @@ int sigblock (int mask)
 {
 {
   sigset_t set, oset;
   sigset_t set, oset;
 
 
-  if (sigset_set_old_mask (&set, mask) < 0)
+  sigset_set_old_mask (&set, mask);
-    return -1;
-
   if (sigprocmask (SIG_BLOCK, &set, &oset) < 0)
   if (sigprocmask (SIG_BLOCK, &set, &oset) < 0)
     return -1;
     return -1;
-
   return sigset_get_old_mask (&oset);
   return sigset_get_old_mask (&oset);
 }
 }
 libc_hidden_def(sigblock)
 libc_hidden_def(sigblock)

+ 3 - 3
libc/signal/sigignore.c

@@ -30,10 +30,10 @@ int sigignore (int sig)
 {
 {
   struct sigaction act;
   struct sigaction act;
 
 
+  memset(&act, 0, sizeof(act));
+  /*__sigemptyset (&act.sa_mask);*/
+  /*act.sa_flags = 0;*/
   act.sa_handler = SIG_IGN;
   act.sa_handler = SIG_IGN;
-  if (__sigemptyset (&act.sa_mask) < 0)
-    return -1;
-  act.sa_flags = 0;
 
 
   return sigaction (sig, &act, NULL);
   return sigaction (sig, &act, NULL);
 }
 }

+ 2 - 3
libc/signal/signal.c

@@ -42,9 +42,8 @@ __bsd_signal (int sig, __sighandler_t handler)
     }
     }
 
 
   act.sa_handler = handler;
   act.sa_handler = handler;
-  if (__sigemptyset (&act.sa_mask) < 0
+  __sigemptyset (&act.sa_mask);
-      || __sigaddset (&act.sa_mask, sig) < 0)
+  __sigaddset (&act.sa_mask, sig);
-    return SIG_ERR;
   act.sa_flags = __sigismember (&_sigintr, sig) ? 0 : SA_RESTART;
   act.sa_flags = __sigismember (&_sigintr, sig) ? 0 : SA_RESTART;
   if (sigaction (sig, &act, &oact) < 0)
   if (sigaction (sig, &act, &oact) < 0)
     return SIG_ERR;
     return SIG_ERR;

+ 6 - 3
libc/signal/sigpause.c

@@ -23,6 +23,7 @@
 #define __FAVOR_BSD
 #define __FAVOR_BSD
 #include <signal.h>
 #include <signal.h>
 #include <stddef.h>		/* For NULL.  */
 #include <stddef.h>		/* For NULL.  */
+#include <string.h>
 
 
 /* libc_hidden_proto(sigprocmask) */
 /* libc_hidden_proto(sigprocmask) */
 /* libc_hidden_proto(sigdelset) */
 /* libc_hidden_proto(sigdelset) */
@@ -37,16 +38,18 @@ int __sigpause (int sig_or_mask, int is_sig)
 {
 {
   sigset_t set;
   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.  */
       /* The modern X/Open implementation is requested.  */
       if (sigprocmask (0, NULL, &set) < 0
       if (sigprocmask (0, NULL, &set) < 0
 	  /* Yes, we call `sigdelset' and not `__sigdelset'.  */
 	  /* Yes, we call `sigdelset' and not `__sigdelset'.  */
 	  || sigdelset (&set, sig_or_mask) < 0)
 	  || sigdelset (&set, sig_or_mask) < 0)
 	return -1;
 	return -1;
     }
     }
-  else if (sigset_set_old_mask (&set, sig_or_mask) < 0)
+  else
-    return -1;
+    sigset_set_old_mask (&set, sig_or_mask);
 
 
   return sigsuspend (&set);
   return sigsuspend (&set);
 }
 }

+ 4 - 14
libc/signal/sigset-cvt-mask.h

@@ -19,22 +19,12 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
    02111-1307 USA.  */
 
 
-static __inline__ int __attribute__ ((unused))
+static __inline__ void __attribute__ ((unused))
 sigset_set_old_mask (sigset_t *set, int mask)
 sigset_set_old_mask (sigset_t *set, int mask)
 {
 {
-  unsigned long int *ptr;
+  if (_SIGSET_NWORDS > 1)
-  int cnt;
+    memset(set, 0, sizeof(*set));
-
+  set->__val[0] = (unsigned int) mask;
-  ptr = &set->__val[0];
-
-  *ptr++ = (unsigned int) mask;
-
-  cnt = _SIGSET_NWORDS - 2;
-  do
-    *ptr++ = 0ul;
-  while (--cnt >= 0);
-
-  return 0;
 }
 }
 
 
 static __inline__ int __attribute__ ((unused))
 static __inline__ int __attribute__ ((unused))

+ 15 - 23
libc/signal/sigset.c

@@ -31,17 +31,20 @@ __sighandler_t sigset (int sig, __sighandler_t disp)
   struct sigaction act, oact;
   struct sigaction act, oact;
   sigset_t set;
   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
 #ifdef SIG_HOLD
   /* Handle SIG_HOLD first.  */
   /* Handle SIG_HOLD first.  */
   if (disp == SIG_HOLD)
   if (disp == SIG_HOLD)
     {
     {
       /* Create an empty signal set.  */
       /* Create an empty signal set.  */
-      if (__sigemptyset (&set) < 0)
+      __sigemptyset (&set);
-	return SIG_ERR;
+      __sigaddset (&set, sig);
-
-      /* Add the specified signal.  */
-      if (__sigaddset (&set, sig) < 0)
-	return SIG_ERR;
 
 
       /* Add the signal set to the current signal mask.  */
       /* Add the signal set to the current signal mask.  */
       if (sigprocmask (SIG_BLOCK, &set, NULL) < 0)
       if (sigprocmask (SIG_BLOCK, &set, NULL) < 0)
@@ -51,27 +54,16 @@ __sighandler_t sigset (int sig, __sighandler_t disp)
     }
     }
 #endif	/* SIG_HOLD */
 #endif	/* SIG_HOLD */
 
 
-  /* Check signal extents to protect __sigismember.  */
+  memset(&act, 0, sizeof(act));
-  if (disp == SIG_ERR || sig < 1 || sig >= NSIG)
+  //__sigemptyset (&act.sa_mask);
-    {
+  //act.sa_flags = 0;
-      __set_errno (EINVAL);
-      return SIG_ERR;
-    }
-
   act.sa_handler = disp;
   act.sa_handler = disp;
-  if (__sigemptyset (&act.sa_mask) < 0)
-    return SIG_ERR;
-  act.sa_flags = 0;
   if (sigaction (sig, &act, &oact) < 0)
   if (sigaction (sig, &act, &oact) < 0)
     return SIG_ERR;
     return SIG_ERR;
 
 
-  /* Create an empty signal set.  */
+  /* Create an empty signal set. Add the specified signal.  */
-  if (__sigemptyset (&set) < 0)
+  __sigemptyset (&set);
-    return SIG_ERR;
+  __sigaddset (&set, sig);
-
-  /* Add the specified signal.  */
-  if (__sigaddset (&set, sig) < 0)
-    return SIG_ERR;
 
 
   /* Remove the signal set from the current signal mask.  */
   /* Remove the signal set from the current signal mask.  */
   if (sigprocmask (SIG_UNBLOCK, &set, NULL) < 0)
   if (sigprocmask (SIG_UNBLOCK, &set, NULL) < 0)

+ 2 - 5
libc/signal/sigsetmask.c

@@ -19,6 +19,7 @@
 #define __UCLIBC_HIDE_DEPRECATED__
 #define __UCLIBC_HIDE_DEPRECATED__
 #include <errno.h>
 #include <errno.h>
 #include <signal.h>
 #include <signal.h>
+#include <string.h>
 
 
 /* libc_hidden_proto(sigprocmask) */
 /* libc_hidden_proto(sigprocmask) */
 
 
@@ -31,13 +32,9 @@ sigsetmask (int mask)
 {
 {
   sigset_t set, oset;
   sigset_t set, oset;
 
 
-  if (sigset_set_old_mask (&set, mask) < 0)
+  sigset_set_old_mask (&set, mask);
-    return -1;
-
   if (sigprocmask (SIG_SETMASK, &set, &oset) < 0)
   if (sigprocmask (SIG_SETMASK, &set, &oset) < 0)
     return -1;
     return -1;
-
-
   return sigset_get_old_mask (&oset);
   return sigset_get_old_mask (&oset);
 }
 }
 libc_hidden_def(sigsetmask)
 libc_hidden_def(sigsetmask)

+ 3 - 3
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) attribute_hidden;
 int __sigwait (const sigset_t *set, int *sig)
 int __sigwait (const sigset_t *set, int *sig)
 {
 {
-	int ret = 1;
+	int ret = sigwaitinfo(set, NULL);
-	if ((ret = sigwaitinfo(set, NULL)) != -1) {
+	if (ret != -1) {
 		*sig = ret;
 		*sig = ret;
 		return 0;
 		return 0;
 	}
 	}
@@ -41,7 +41,7 @@ int __sigwait (const sigset_t *set, int *sig)
 /* libc_hidden_proto(sigaction) */
 /* libc_hidden_proto(sigaction) */
 /* libc_hidden_proto(sigsuspend) */
 /* 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)
 static void ignore_signal(int sig)
 {
 {
 	was_sig = sig;
 	was_sig = sig;

+ 2 - 4
libc/signal/sysv_signal.c

@@ -47,10 +47,8 @@ __sighandler_t __sysv_signal (int sig, __sighandler_t handler)
     }
     }
 
 
   act.sa_handler = handler;
   act.sa_handler = handler;
-  if (__sigemptyset (&act.sa_mask) < 0)
+  __sigemptyset (&act.sa_mask);
-    return SIG_ERR;
+  act.sa_flags = (SA_ONESHOT | SA_NOMASK | SA_INTERRUPT) & ~SA_RESTART;
-  act.sa_flags = SA_ONESHOT | SA_NOMASK | SA_INTERRUPT;
-  act.sa_flags &= ~SA_RESTART;
   if (sigaction (sig, &act, &oact) < 0)
   if (sigaction (sig, &act, &oact) < 0)
     return SIG_ERR;
     return SIG_ERR;
 
 

+ 6 - 5
libc/stdlib/abort.c

@@ -60,9 +60,9 @@ void abort(void)
 	__UCLIBC_MUTEX_LOCK_CANCEL_UNSAFE(mylock);
 	__UCLIBC_MUTEX_LOCK_CANCEL_UNSAFE(mylock);
 
 
 	/* Unmask SIGABRT to be sure we can get it */
 	/* Unmask SIGABRT to be sure we can get it */
-	if (__sigemptyset(&sigs) == 0 && __sigaddset(&sigs, SIGABRT) == 0) {
+	__sigemptyset(&sigs);
-		sigprocmask(SIG_UNBLOCK, &sigs, (sigset_t *) NULL);
+	__sigaddset(&sigs, SIGABRT);
-	}
+	sigprocmask(SIG_UNBLOCK, &sigs, (sigset_t *) NULL);
 
 
 	while (1) {
 	while (1) {
 		/* Try to suicide with a SIGABRT */
 		/* Try to suicide with a SIGABRT */
@@ -91,9 +91,10 @@ abort_it:
 
 
 			been_there_done_that++;
 			been_there_done_that++;
 			memset(&act, '\0', sizeof(struct sigaction));
 			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);
 			__sigfillset(&act.sa_mask);
-			act.sa_flags = 0;
+			/*act.sa_flags = 0; - memset did it */
 			sigaction(SIGABRT, &act, NULL);
 			sigaction(SIGABRT, &act, NULL);
 
 
 			goto abort_it;
 			goto abort_it;

+ 2 - 3
libc/sysdeps/linux/alpha/sigprocmask.c

@@ -51,10 +51,9 @@ sigprocmask (int how, const sigset_t *set, sigset_t *oset)
 
 
   if (oset)
   if (oset)
     {
     {
+      if (_SIGSET_NWORDS > 1)
+        memset(oset, 0, sizeof(*oset));
       oset->__val[0] = result;
       oset->__val[0] = result;
-      result = _SIGSET_NWORDS;
-      while (--result > 0)
-	oset->__val[result] = 0;
     }
     }
   return 0;
   return 0;
 }
 }

+ 4 - 3
libc/sysdeps/linux/common/ssp.c

@@ -57,10 +57,11 @@ static void block_signals(void)
 	sigprocmask(SIG_BLOCK, &mask, NULL);	/* except SSP_SIGTYPE */
 	sigprocmask(SIG_BLOCK, &mask, NULL);	/* except SSP_SIGTYPE */
 
 
 	/* Make the default handler associated with the signal handler */
 	/* 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 */
 	sigfillset(&sa.sa_mask);	/* Block all signals */
-	sa.sa_flags = 0;
+	/* sa.sa_flags = 0; - memset did it */
-	sa.sa_handler = SIG_DFL;
+	if (SIG_DFL) /* if it's constant zero, it's already done */
+		sa.sa_handler = SIG_DFL;
 	sigaction(SSP_SIGTYPE, &sa, NULL);
 	sigaction(SSP_SIGTYPE, &sa, NULL);
 }
 }
 
 

+ 8 - 8
libc/unistd/sleep.c

@@ -66,9 +66,9 @@ unsigned int sleep (unsigned int seconds)
     /* Linux will wake up the system call, nanosleep, when SIGCHLD
     /* Linux will wake up the system call, nanosleep, when SIGCHLD
        arrives even if SIGCHLD is ignored.  We have to deal with it
        arrives even if SIGCHLD is ignored.  We have to deal with it
        in libc.  We block SIGCHLD first.  */
        in libc.  We block SIGCHLD first.  */
-    if (__sigemptyset (&set) < 0
+    __sigemptyset (&set);
-	    || __sigaddset (&set, SIGCHLD) < 0
+    __sigaddset (&set, SIGCHLD);
-	    || sigprocmask (SIG_BLOCK, &set, &oset))
+    if (sigprocmask (SIG_BLOCK, &set, &oset))
 	return -1;
 	return -1;
 
 
     /* If SIGCHLD is already blocked, we don't have to do anything.  */
     /* 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;
 	int saved_errno;
 	struct sigaction oact;
 	struct sigaction oact;
 
 
-	if (__sigemptyset (&set) < 0 || __sigaddset (&set, SIGCHLD) < 0)
+	__sigemptyset (&set);
-	    return -1;
+	__sigaddset (&set, SIGCHLD);
 
 
 	/* We get the signal handler for SIGCHLD.  */
 	/* We get the signal handler for SIGCHLD.  */
 	if (sigaction (SIGCHLD, (struct sigaction *) NULL, &oact) < 0)
 	if (sigaction (SIGCHLD, (struct sigaction *) NULL, &oact) < 0)
@@ -136,9 +136,9 @@ unsigned int sleep (unsigned int seconds)
 	return 0;
 	return 0;
 
 
     /* block SIGALRM */
     /* block SIGALRM */
-    if (__sigemptyset (&set) < 0
+    __sigemptyset (&set);
-	    || __sigaddset (&set, SIGALRM) < 0
+    __sigaddset (&set, SIGALRM);
-	    || sigprocmask (SIG_BLOCK, &set, &oset))
+    if (sigprocmask (SIG_BLOCK, &set, &oset))
 	return seconds;
 	return seconds;
 
 
     act.sa_handler = sleep_alarm_handler;
     act.sa_handler = sleep_alarm_handler;

+ 5 - 3
libpthread/linuxthreads.old/pthread.c

@@ -928,9 +928,11 @@ void __pthread_kill_other_threads_np(void)
   /* Reset the signal handlers behaviour for the signals the
   /* Reset the signal handlers behaviour for the signals the
      implementation uses since this would be passed to the new
      implementation uses since this would be passed to the new
      process.  */
      process.  */
-  sigemptyset(&sa.sa_mask);
+  memset(&sa, 0, sizeof(sa));
-  sa.sa_flags = 0;
+  /*sigemptyset(&sa.sa_mask);*/
-  sa.sa_handler = SIG_DFL;
+  /*sa.sa_flags = 0;*/
+  if (SIG_DFL) /* if it's constant zero, it's already done */
+    sa.sa_handler = SIG_DFL;
   __libc_sigaction(__pthread_sig_restart, &sa, NULL);
   __libc_sigaction(__pthread_sig_restart, &sa, NULL);
   __libc_sigaction(__pthread_sig_cancel, &sa, NULL);
   __libc_sigaction(__pthread_sig_cancel, &sa, NULL);
   if (__pthread_sig_debug > 0)
   if (__pthread_sig_debug > 0)

+ 5 - 3
libpthread/linuxthreads/pthread.c

@@ -1151,9 +1151,11 @@ void __pthread_kill_other_threads_np(void)
   /* Reset the signal handlers behaviour for the signals the
   /* Reset the signal handlers behaviour for the signals the
      implementation uses since this would be passed to the new
      implementation uses since this would be passed to the new
      process.  */
      process.  */
-  sigemptyset(&sa.sa_mask);
+  memset(&sa, 0, sizeof(sa));
-  sa.sa_flags = 0;
+  /*sigemptyset(&sa.sa_mask);*/
-  sa.sa_handler = SIG_DFL;
+  /*sa.sa_flags = 0;*/
+  if (SIG_DFL) /* if it's constant zero, it's already done too */
+    sa.sa_handler = SIG_DFL;
   __libc_sigaction(__pthread_sig_restart, &sa, NULL);
   __libc_sigaction(__pthread_sig_restart, &sa, NULL);
   __libc_sigaction(__pthread_sig_cancel, &sa, NULL);
   __libc_sigaction(__pthread_sig_cancel, &sa, NULL);
   if (__pthread_sig_debug > 0)
   if (__pthread_sig_debug > 0)