2
* FreeRDP: A Remote Desktop Protocol Client
5
* Copyright 2011 Shea Levy <shea@shealevy.com>
7
* Licensed under the Apache License, Version 2.0 (the "License");
8
* you may not use this file except in compliance with the License.
9
* You may obtain a copy of the License at
11
* http://www.apache.org/licenses/LICENSE-2.0
13
* Unless required by applicable law or agreed to in writing, software
14
* distributed under the License is distributed on an "AS IS" BASIS,
15
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
* See the License for the specific language governing permissions and
17
* limitations under the License.
21
#include <freerdp/utils/signal.h>
24
int freerdp_handle_signals(void)
30
volatile sig_atomic_t terminal_needs_reset = 0;
31
int terminal_fildes = 0;
32
struct termios orig_flags;
33
struct termios new_flags;
35
static void fatal_handler(int signum)
37
struct sigaction default_sigaction;
40
if (terminal_needs_reset)
41
tcsetattr(terminal_fildes, TCSAFLUSH, &orig_flags);
43
default_sigaction.sa_handler = SIG_DFL;
44
sigfillset(&(default_sigaction.sa_mask));
45
default_sigaction.sa_flags = 0;
47
sigaction(signum, &default_sigaction, NULL);
49
sigemptyset(&this_mask);
50
sigaddset(&this_mask, signum);
51
pthread_sigmask(SIG_UNBLOCK, &this_mask, NULL);
55
int freerdp_handle_signals(void)
57
const int fatal_signals[] = {
94
struct sigaction orig_sigaction, fatal_sigaction;
96
sigfillset(&(fatal_sigaction.sa_mask));
97
sigdelset(&(fatal_sigaction.sa_mask), SIGCONT);
98
pthread_sigmask(SIG_BLOCK, &(fatal_sigaction.sa_mask), &orig_set);
100
fatal_sigaction.sa_handler = fatal_handler;
101
fatal_sigaction.sa_flags = 0;
103
for (signal_index = 0;
104
signal_index < (sizeof fatal_signals / sizeof fatal_signals[0]);
106
if (sigaction(fatal_signals[signal_index],
107
NULL, &orig_sigaction) == 0)
108
if (orig_sigaction.sa_handler != SIG_IGN)
109
sigaction(fatal_signals[signal_index],
110
&fatal_sigaction, NULL);
112
pthread_sigmask(SIG_SETMASK, &orig_set, NULL);