/* Since we don't want any of the worker threads to catch any signals, we must mask off any * potential signals here after creating the threads. If any of the created threads catch a signal, * they'd eventually call join on themselves, causing a deadlock. */ void thread_signal_init() { sigset_t thread_sigmask; int rc; if ((rc = sigfillset(&thread_sigmask))) { LogError("sigfillset failed: error=%d: %s", rc, strerror(rc)); LogError("worker thread %ld is exiting prematurely", THREAD_ID); THREAD_EXIT(NULL); } if ((rc = THREAD_SET_SIGNAL_MASK(SIG_BLOCK, &thread_sigmask, NULL))) { LogError("Setting thread sigmask failed: error=%d: %s", rc, strerror(rc)); LogError("worker thread %ld is exiting prematurely", THREAD_ID); THREAD_EXIT(NULL); } }
static TSS_RESULT signals_init(void) { int rc; sigset_t sigmask; struct sigaction sa; sigemptyset(&sigmask); if ((rc = sigaddset(&sigmask, SIGTERM))) { LogError("sigaddset: %s", strerror(errno)); return TCSERR(TSS_E_INTERNAL_ERROR); } if ((rc = sigaddset(&sigmask, SIGHUP))) { LogError("sigaddset: %s", strerror(errno)); return TCSERR(TSS_E_INTERNAL_ERROR); } if ((rc = THREAD_SET_SIGNAL_MASK(SIG_UNBLOCK, &sigmask, NULL))) { LogError("Setting thread signal mask: %s", strerror(rc)); return TCSERR(TSS_E_INTERNAL_ERROR); } sa.sa_flags = 0; sigemptyset(&sa.sa_mask); sa.sa_handler = tcsd_signal_term; if ((rc = sigaction(SIGTERM, &sa, NULL))) { LogError("signal SIGTERM not registered: %s", strerror(errno)); return TCSERR(TSS_E_INTERNAL_ERROR); } sa.sa_handler = tcsd_signal_hup; if ((rc = sigaction(SIGHUP, &sa, NULL))) { LogError("signal SIGHUP not registered: %s", strerror(errno)); return TCSERR(TSS_E_INTERNAL_ERROR); } return TSS_SUCCESS; }