Changes in signal.c [a7fac14:1d21d9f]
Legend:
- Unmodified
- Added
- Removed
-
signal.c
ra7fac14 r1d21d9f 1 1 #include <errno.h> 2 #include <glib.h>3 2 #include <pthread.h> 4 3 #include <signal.h> … … 14 13 static void *signal_thread_func(void *data); 15 14 16 static void dummy_handler(int signum) 17 { 18 /* Do nothing. This should never get called. It'd be nice to report the error 19 * or something, but you can't have nice things in a signal handler. */ 20 } 21 22 #define OR_DIE(s, syscall) \ 23 G_STMT_START { \ 24 if ((syscall) == -1) { \ 25 perror((s)); \ 26 exit(1); \ 27 } \ 28 } G_STMT_END 29 30 /* Initializes the signal thread to listen for 'signals' on a dedicated 15 /* Initializes the signal thread to listen for 'set' on a dedicated 31 16 * thread. 'callback' is called *on the signal thread* when a signal 32 17 * is received. … … 34 19 * This function /must/ be called before any other threads are 35 20 * created. (Otherwise the signals will not get blocked correctly.) */ 36 void owl_signal_init(const int *signals, int num_signals, void (*callback)(const siginfo_t*, void*), void *data) { 37 struct sigaction sig_dummy = { .sa_handler = dummy_handler }; 21 void owl_signal_init(const sigset_t *set, void (*callback)(const siginfo_t*, void*), void *data) { 38 22 int ret; 39 int i;40 23 24 signal_set = *set; 41 25 signal_cb = callback; 42 26 signal_cbdata = data; 43 44 /* Stuff the signals into our sigset_t. Also assign all of them to a dummy45 * handler. Otherwise, if their default is SIG_IGN, they will get dropped if46 * delivered while processing. On Solaris, they will not get delivered at47 * all. */48 OR_DIE("sigemptyset", sigemptyset(&signal_set));49 for (i = 0; i < num_signals; i++) {50 OR_DIE("sigaddset", sigaddset(&signal_set, signals[i]));51 OR_DIE("sigaction", sigaction(signals[i], &sig_dummy, NULL));52 }53 54 27 /* Block these signals in all threads, so we can get them. */ 55 if ((ret = pthread_sigmask(SIG_BLOCK, &signal_set, NULL)) != 0) {28 if ((ret = pthread_sigmask(SIG_BLOCK, set, NULL)) != 0) { 56 29 errno = ret; 57 30 perror("pthread_sigmask"); 58 exit(1);59 31 } 60 32 /* Spawn a dedicated thread to sigwait. */
Note: See TracChangeset
for help on using the changeset viewer.