public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix linuxthreads sigaction
@ 2003-11-04 18:26 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2003-11-04 18:26 UTC (permalink / raw)
  To: Ulrich Drepper, Roland McGrath; +Cc: Glibc hackers

Hi!

The following patch seems to fix testcase in
http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=108634
That test doesn't use any threads, yet segfaults when linked
with LT -lpthread and doesn't when linked only against -lc.
Still, weird thing can happen if two sigaction calls are called at once
in different threads, but that was never atomic in LT.

2003-11-04  Jakub Jelinek  <jakub@redhat.com>

	* signals.c (__pthread_sigaction): Set __sighandler[sig].old before
	__libc_sigaction if it has been one of the special values before.

--- libc/linuxthreads/signals.c.jj	2003-01-07 01:09:22.000000000 +0100
+++ libc/linuxthreads/signals.c	2003-10-31 23:44:48.000000000 +0100
@@ -78,6 +78,7 @@ int __pthread_sigaction(int sig, const s
 {
   struct sigaction newact;
   struct sigaction *newactp;
+  __sighandler_t old = SIG_DFL;
 
   if (sig == __pthread_sig_restart ||
       sig == __pthread_sig_cancel ||
@@ -86,6 +87,8 @@ int __pthread_sigaction(int sig, const s
       __set_errno (EINVAL);
       return -1;
     }
+  if (sig > 0 && sig < NSIG)
+    old = (__sighandler_t) __sighandler[sig].old;
   if (act)
     {
       newact = *act;
@@ -96,21 +99,27 @@ int __pthread_sigaction(int sig, const s
 	    newact.sa_handler = (__sighandler_t) __pthread_sighandler_rt;
 	  else
 	    newact.sa_handler = (__sighandler_t) __pthread_sighandler;
+	  if (old == SIG_IGN || old == SIG_DFL || old == SIG_ERR)
+	    __sighandler[sig].old = (arch_sighandler_t) act->sa_handler;
 	}
       newactp = &newact;
     }
   else
     newactp = NULL;
   if (__libc_sigaction(sig, newactp, oact) == -1)
-    return -1;
+    {
+      if (act)
+	__sighandler[sig].old = (arch_sighandler_t) old;
+      return -1;
+    }
   if (sig > 0 && sig < NSIG)
     {
       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;
+	  && old != SIG_ERR)
+	oact->sa_handler = old;
       if (act)
 	/* For the assignment it does not matter whether it's a normal
 	   or real-time signal.  */

	Jakub

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-11-04 18:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-04 18:26 [PATCH] Fix linuxthreads sigaction Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).