-static volatile shutdown_t __shutdown= SHUTDOWN_RUNNING;
-pthread_mutex_t shutdown_mutex= PTHREAD_MUTEX_INITIALIZER;
-
-static bool is_shutdown()
-{
- bool ret;
- pthread_mutex_lock(&shutdown_mutex);
- ret= bool(__shutdown != SHUTDOWN_RUNNING);
- pthread_mutex_unlock(&shutdown_mutex);
-
- return ret;
-}
-
-static void set_shutdown(shutdown_t arg)
-{
- pthread_mutex_lock(&shutdown_mutex);
- __shutdown= arg;
- pthread_mutex_unlock(&shutdown_mutex);
-}
-
-static void *sig_thread(void *arg)
-{
- sigset_t *set= (sigset_t *) arg;
-
- while (is_shutdown())
- {
- int sig;
- int error;
- while ((error= sigwait(set, &sig)) == EINTR) ;
-
- switch (sig)
- {
- case SIGSEGV:
- case SIGINT:
- case SIGABRT:
- Error << "Signal handling thread got signal " << strsignal(sig);
- set_shutdown(SHUTDOWN_FORCED);
- break;
-
- default:
- Error << "Signal handling thread got unexpected signal " << strsignal(sig);
- case SIGUSR1:
- break;
- }
- }
-
- return NULL;
-}
-
-
-static void setup_signals(pthread_t& thread)
-{
- sigset_t set;
-
- sigemptyset(&set);
- sigaddset(&set, SIGSEGV);
- sigaddset(&set, SIGABRT);
- sigaddset(&set, SIGINT);
- sigaddset(&set, SIGUSR1);
-
- int error;
- if ((error= pthread_sigmask(SIG_BLOCK, &set, NULL)) != 0)
- {
- Error << " died during pthread_sigmask(" << strerror(error) << ")";
- exit(EXIT_FAILURE);
- }
-
- if ((error= pthread_create(&thread, NULL, &sig_thread, (void *) &set)) != 0)
- {
- Error << " died during pthread_create(" << strerror(error) << ")";
- exit(EXIT_FAILURE);
- }
-}
-
-