From: Chaskiel M Grundman Date: Mon, 2 Jun 2003 23:49:01 +0000 (+0000) Subject: STABLE12-softsig-update-20030602 X-Git-Tag: openafs-stable-1_2_10~49 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=6ca1262b8a4a2afddd4bee2ee0beed87c25fdbde;p=packages%2Fo%2Fopenafs.git STABLE12-softsig-update-20030602 FIXES 1435 changes to help us die and to unblock all signals to wait on (cherry picked from commit ee00daa36432ba6eac6004c6c691aaab98c0e62f) --- diff --git a/src/util/softsig.c b/src/util/softsig.c index 886a61f76..6d8a9f9b2 100644 --- a/src/util/softsig.c +++ b/src/util/softsig.c @@ -14,34 +14,59 @@ #include #include +#include "pthread_nosigs.h" + static pthread_t softsig_tid; static struct { void (*handler) (int); int pending; + int fatal; + int inited; } softsig_sigs[NSIG]; static void * softsig_thread (void *arg) { - sigset_t ss; + sigset_t ss,os; + int i; sigemptyset (&ss); + /* get the list of signals _not_ blocked by AFS_SIGSET_CLEAR() */ + pthread_sigmask (SIG_BLOCK, &ss, &os); + pthread_sigmask (SIG_SETMASK, &os, NULL); sigaddset (&ss, SIGUSR1); + for (i = 0; i < NSIG; i++) { + if (!sigismember(&os, i) && i != SIGSTOP && i != SIGKILL) { + sigaddset(&ss, i); + softsig_sigs[i].fatal = 1; + } + } while (1) { void (*h) (int) = NULL; - int i, sigw; + int sigw; - for (i = 0; i < NSIG; i++) + h = NULL; + + for (i = 0; i < NSIG; i++) { + if (softsig_sigs[i].handler && !softsig_sigs[i].inited) { + sigaddset(&ss, i); + softsig_sigs[i].inited = 1; + } if (softsig_sigs[i].pending) { - softsig_sigs[i].pending = 0; - h = softsig_sigs[i].handler; - break; + softsig_sigs[i].pending = 0; + h = softsig_sigs[i].handler; + break; } - - if (i == NSIG) - assert (0 == sigwait (&ss, &sigw)); - else if (h) + } + if (i == NSIG) { + sigwait (&ss, &sigw); + if (sigw != SIGUSR1) { + if (softsig_sigs[sigw].fatal) + exit(0); + softsig_sigs[sigw].pending=1; + } + } else if (h) h (i); } } @@ -49,22 +74,18 @@ softsig_thread (void *arg) void softsig_init () { - sigset_t ss, os; - - sigemptyset (&ss); - sigaddset (&ss, SIGUSR1); - - /* Set mask right away, so we don't accidentally SIGUSR1 the - * softsig thread and cause an exit (default action). - */ - assert (0 == pthread_sigmask (SIG_BLOCK, &ss, &os)); - assert (0 == pthread_create (&softsig_tid, NULL, &softsig_thread, NULL)); - assert (0 == pthread_sigmask (SIG_SETMASK, &os, NULL)); + int rc; + AFS_SIGSET_DECL; + AFS_SIGSET_CLEAR(); + rc = pthread_create (&softsig_tid, NULL, &softsig_thread, NULL); + assert(0 == rc); + AFS_SIGSET_RESTORE(); } static void softsig_handler (int signo) { + signal (signo, softsig_handler); softsig_sigs[signo].pending = 1; pthread_kill (softsig_tid, SIGUSR1); } @@ -73,7 +94,9 @@ void softsig_signal (int signo, void (*handler) (int)) { softsig_sigs[signo].handler = handler; + softsig_sigs[signo].inited = 0; signal (signo, softsig_handler); + pthread_kill (softsig_tid, SIGUSR1); } #if defined(TEST)