/* * Thread function waiting for signals and processing them. * Wait for signals in signal set. The semantics of sigwait() require that all * threads (including the thread calling sigwait()) have the signal masked, for * reliable operation. Otherwise, a signal that arrives while this thread is * not blocked in sigwait() might be delivered to another thread. */ void * signal_handling_thread (void *arg) { int signo; while (1) { sigwait (&signal_set, &signo); switch (signo) { case SIGINT: if (nmc_get_in_readline ()) { /* Don't quit when in readline, only signal we received SIGINT */ pthread_mutex_lock (&sigint_mutex); nmcli_sigint = TRUE; pthread_mutex_unlock (&sigint_mutex); } else { /* We can quit nmcli */ tcsetattr (STDIN_FILENO, TCSADRAIN, &termios_orig); nmc_cleanup_readline (); g_print (_("\nError: nmcli terminated by signal %s (%d)\n"), strsignal (signo), signo); exit (1); } break; case SIGQUIT: case SIGTERM: tcsetattr (STDIN_FILENO, TCSADRAIN, &termios_orig); nmc_cleanup_readline (); if (!nmcli_sigquit_internal) g_print (_("\nError: nmcli terminated by signal %s (%d)\n"), strsignal (signo), signo); exit (1); break; default: break; } } return NULL; }
/* * Thread function waiting for signals and processing them. * Wait for signals in signal set. The semantics of sigwait() require that all * threads (including the thread calling sigwait()) have the signal masked, for * reliable operation. Otherwise, a signal that arrives while this thread is * not blocked in sigwait() might be delivered to another thread. */ void * signal_handling_thread (void *arg) { int signo; while (1) { sigwait (&signal_set, &signo); switch (signo) { case SIGINT: case SIGQUIT: case SIGTERM: nmc_cleanup_readline (); printf (_("\nError: nmcli terminated by signal %d."), signo); exit (1); break; default: break; } } return NULL; }
void nmc_exit (void) { tcsetattr (STDIN_FILENO, TCSADRAIN, &termios_orig); nmc_cleanup_readline (); exit (1); }