sigaction in libpthread returns wrong old handler

Andreas Schwab schwab@suse.de
Fri Jan 11 04:17:00 GMT 2002


When sigaction in libpthread is called the first time for a signal we
don't know whether the old signal handler is SIG_DFL or SIG_IGN, so we
must return the value that the kernel reports.

Andreas.

2002-01-11  Andreas Schwab  <schwab@suse.de>

	* signals.c (sighandler): Initialize all elements to SIG_ERR.
	(__sigaction): Don't use value from sighandler if it is SIG_ERR.

--- linuxthreads/signals.c.~1.22.~	Tue Apr 17 10:56:07 2001
+++ linuxthreads/signals.c	Fri Jan 11 13:12:39 2002
@@ -74,7 +74,7 @@
 {
   arch_sighandler_t old;
   void (*rt) (int, struct siginfo *, struct ucontext *);
-} sighandler[NSIG];
+} sighandler[NSIG] = { [1 ... NSIG - 1] = { (arch_sighandler_t) SIG_ERR } };
 
 /* The wrapper around user-provided signal handlers */
 static void pthread_sighandler(int signo, SIGCONTEXT ctx)
@@ -157,10 +157,14 @@
     return -1;
   if (sig > 0 && sig < NSIG)
     {
-      if (oact != NULL)
+      if (oact != NULL
+	  /* We may have inherited SIG_IGN from the parent, so return the
+	     kernel's idea of the signal handler the first time
+	     through.  */
+	  && (__sighandler_t) sighandler[sig].old != SIG_ERR)
 	oact->sa_handler = (__sighandler_t) sighandler[sig].old;
       if (act)
-	/* For the assignment is does not matter whether it's a normal
+	/* For the assignment it does not matter whether it's a normal
 	   or real-time signal.  */
 	sighandler[sig].old = (arch_sighandler_t) act->sa_handler;
     }

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE GmbH, Deutschherrnstr. 15-19, D-904229 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



More information about the Libc-hacker mailing list