2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
9 * Portions Copyright (c) 2003 Apple Computer, Inc.
12 #include <afsconfig.h>
13 #include <afs/param.h>
14 #include <afs/procmgmt.h> /* Must be before roken.h */
21 #include "pthread_nosigs.h"
23 /*------------------------------------------------------------------------
24 * Under Darwin 6.x (including 7.0), sigwait() is broken, so we use
25 * sigsuspend() instead. We also don't block signals we don't know
26 * about, so they should kill us, rather than us returning zero status.
27 *------------------------------------------------------------------------*/
29 static pthread_t softsig_tid;
31 void (*handler) (int);
33 #if !(defined(AFS_DARWIN_ENV) || (defined(AFS_NBSD_ENV) && !defined(AFS_NBSD50_ENV)))
35 #endif /* !defined(AFS_DARWIN_ENV) || !defined(AFS_NBSD_ENV) */
40 softsig_thread(void *arg)
46 /* get the list of signals _not_ blocked by AFS_SIGSET_CLEAR() */
47 pthread_sigmask(SIG_BLOCK, &ss, &os);
48 pthread_sigmask(SIG_SETMASK, &os, NULL);
49 sigaddset(&ss, SIGUSR1);
50 #if defined(AFS_DARWIN_ENV) || (defined(AFS_NBSD_ENV) && !defined(AFS_NBSD50_ENV))
51 pthread_sigmask (SIG_BLOCK, &ss, NULL);
52 sigdelset (&os, SIGUSR1);
53 #elif !defined(AFS_HPUX_ENV)
54 /* On HPUX, don't wait for 'critical' signals, as things such as
55 * SEGV won't cause a core, then. Some non-HPUX platforms may need
56 * this, though, since apparently if we wait on some signals but not
57 * e.g. SEGV, the softsig thread will still wait around when the
58 * other threads were killed by the SEGV. */
59 for (i = 0; i < NSIG; i++) {
60 if (!sigismember(&os, i) && i != SIGSTOP && i != SIGKILL) {
62 softsig_sigs[i].fatal = 1;
65 #endif /* defined(AFS_DARWIN_ENV) || defined(AFS_NBSD_ENV) */
69 #if !defined(AFS_DARWIN_ENV) && (!defined(AFS_NBSD_ENV) || defined(AFS_NBSD50_ENV))
75 for (i = 0; i < NSIG; i++) {
76 if (softsig_sigs[i].handler && !softsig_sigs[i].inited) {
78 #if defined(AFS_DARWIN_ENV) || (defined(AFS_NBSD_ENV) && !defined(AFS_NBSD50_ENV))
79 pthread_sigmask (SIG_BLOCK, &ss, NULL);
81 #endif /* defined(AFS_DARWIN_ENV) || defined(AFS_NBSD_ENV) */
82 softsig_sigs[i].inited = 1;
84 if (softsig_sigs[i].pending) {
85 softsig_sigs[i].pending = 0;
86 h = softsig_sigs[i].handler;
91 #if defined(AFS_DARWIN_ENV) || (defined(AFS_NBSD_ENV) && !defined(AFS_NBSD50_ENV))
93 #else /* !defined(AFS_DARWIN_ENV) && !defined(AFS_NBSD_ENV) */
95 if (sigw != SIGUSR1) {
96 if (softsig_sigs[sigw].fatal)
98 softsig_sigs[sigw].pending = 1;
100 #endif /* defined(AFS_DARWIN_ENV) || defined(AFS_NBSD_ENV) */
108 softsig_usr1(int signo)
110 signal (SIGUSR1, softsig_usr1);
119 rc = pthread_create(&softsig_tid, NULL, &softsig_thread, NULL);
121 AFS_SIGSET_RESTORE();
122 signal (SIGUSR1, softsig_usr1);
126 softsig_handler(int signo)
128 signal(signo, softsig_handler);
129 softsig_sigs[signo].pending = 1;
130 pthread_kill(softsig_tid, SIGUSR1);
134 softsig_signal(int signo, void (*handler) (int))
136 softsig_sigs[signo].handler = handler;
137 softsig_sigs[signo].inited = 0;
138 signal(signo, softsig_handler);
139 pthread_kill(softsig_tid, SIGUSR1);
146 printf("foo, signo = %d, tid = %d\n", signo, pthread_self());
150 main(int argc, char **argv)
153 softsig_signal(SIGINT, print_foo);
154 printf("main is tid %d\n", pthread_self());