freerdp_handle_signals: Reset the terminal for a fatal signal

This commit is contained in:
Shea Levy 2011-09-28 01:15:42 -04:00
parent 6ad931bebd
commit 77bffc4afb

View File

@ -17,12 +17,49 @@
* limitations under the License.
*/
#include <stddef.h>
#include <freerdp/utils/signal.h>
volatile sig_atomic_t terminal_needs_reset = 0;
int terminal_fildes = 0;
struct termios orig_flags;
struct termios new_flags;
static void fatal_handler(int signum)
{
struct sigaction default_sigaction;
if (terminal_needs_reset)
tcsetattr(terminal_fildes, TCSAFLUSH, &orig_flags);
default_sigaction.sa_handler = SIG_DFL;
sigfillset(&(default_sigaction.sa_mask));
default_sigaction.sa_flags = 0;
sigaction(signum, &default_sigaction, NULL);
raise(signum);
}
void freerdp_handle_signals(void)
{
const int fatal_signals[] = { SIGINT };
int signal_index;
sigset_t orig_set;
struct sigaction orig_sigaction, fatal_sigaction;
sigfillset(&(fatal_sigaction.sa_mask));
pthread_sigmask(SIG_BLOCK, &(fatal_sigaction.sa_mask), &orig_set);
fatal_sigaction.sa_handler = fatal_handler;
fatal_sigaction.sa_flags = 0;
for (signal_index = 0;
signal_index < (sizeof fatal_signals / sizeof fatal_signals[0]);
signal_index++)
if (sigaction(fatal_signals[signal_index],
NULL, &orig_sigaction) == 0)
if (orig_sigaction.sa_handler != SIG_IGN)
sigaction(fatal_signals[signal_index],
&fatal_sigaction, NULL);
pthread_sigmask(SIG_SETMASK, &orig_set, NULL);
}