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>
15 #define _POSIX_PTHREAD_SEMANTICS
16 #include <afs/param.h>
24 #include <afs/procmgmt.h>
28 #include "pthread_nosigs.h"
30 /*------------------------------------------------------------------------
31 * Under Darwin 6.x (including 7.0), sigwait() is broken, so we use
32 * sigsuspend() instead. We also don't block signals we don't know
33 * about, so they should kill us, rather than us returning zero status.
34 *------------------------------------------------------------------------*/
36 static pthread_t softsig_tid;
38 void (*handler) (int);
40 #if !defined(AFS_DARWIN60_ENV) || defined(AFS_NBSD30_ENV) || !defined(AFS_NBSD_ENV)
42 #endif /* !defined(AFS_DARWIN60_ENV) || !defined(AFS_NBSD_ENV) */
47 softsig_thread(void *arg)
53 /* get the list of signals _not_ blocked by AFS_SIGSET_CLEAR() */
54 pthread_sigmask(SIG_BLOCK, &ss, &os);
55 pthread_sigmask(SIG_SETMASK, &os, NULL);
56 sigaddset(&ss, SIGUSR1);
57 #if defined(AFS_DARWIN60_ENV) || (defined(AFS_NBSD_ENV) && !defined(AFS_NBSD30_ENV))
58 pthread_sigmask (SIG_BLOCK, &ss, NULL);
59 sigdelset (&os, SIGUSR1);
60 #else /* !defined(AFS_DARWIN60_ENV) && !defined(AFS_NBSD_ENV) */
61 for (i = 0; i < NSIG; i++) {
62 if (!sigismember(&os, i) && i != SIGSTOP && i != SIGKILL) {
64 softsig_sigs[i].fatal = 1;
67 #endif /* defined(AFS_DARWIN60_ENV) || defined(AFS_NBSD_ENV) */
75 for (i = 0; i < NSIG; i++) {
76 if (softsig_sigs[i].handler && !softsig_sigs[i].inited) {
78 #if defined(AFS_DARWIN60_ENV) || (defined(AFS_NBSD_ENV) && !defined(AFS_NBSD30_ENV))
79 pthread_sigmask (SIG_BLOCK, &ss, NULL);
81 #endif /* defined(AFS_DARWIN60_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_DARWIN60_ENV) || (defined(AFS_NBSD_ENV) && !defined(AFS_NBSD30_ENV))
93 #else /* !defined(AFS_DARWIN60_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_DARWIN60_ENV) || defined(AFS_NBSD_ENV) */
107 softsig_usr1(int signo)
109 signal (SIGUSR1, softsig_usr1);
118 rc = pthread_create(&softsig_tid, NULL, &softsig_thread, NULL);
120 AFS_SIGSET_RESTORE();
121 signal (SIGUSR1, softsig_usr1);
125 softsig_handler(int signo)
127 signal(signo, softsig_handler);
128 softsig_sigs[signo].pending = 1;
129 pthread_kill(softsig_tid, SIGUSR1);
133 softsig_signal(int signo, void (*handler) (int))
135 softsig_sigs[signo].handler = handler;
136 softsig_sigs[signo].inited = 0;
137 signal(signo, softsig_handler);
138 pthread_kill(softsig_tid, SIGUSR1);
145 printf("foo, signo = %d, tid = %d\n", signo, pthread_self());
152 softsig_signal(SIGINT, print_foo);
153 printf("main is tid %d\n", pthread_self());