-
Notifications
You must be signed in to change notification settings - Fork 0
/
linuxsignals.h
64 lines (58 loc) · 1.84 KB
/
linuxsignals.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* Copyright (C) 2008 Ali Shah <[email protected]>
*
* This file is part of the Qlix project on http://berlios.de
*
* This file may be used under the terms of the GNU General Public
* License version 2.0 as published by the Free Software Foundation
* and appearing in the file COPYING included in the packaging of
* this file.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License version 2.0 for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <signal.h>
#include <stdio.h>
extern MtpSubSystem _subSystem;
void handler(int sig)
{
sigset_t set;
sigset_t previous_set;
sigaddset(&set, SIGINT);
sigaddset(&set, SIGFPE);
sigaddset(&set, SIGQUIT);
sigaddset(&set, SIGSEGV);
sigaddset(&set, SIGHUP);
sigaddset(&set, SIGKILL);
sigprocmask(SIG_BLOCK, &set,&previous_set);
_subSystem.ReleaseDevices();
printf("Ouch! - Qlix received signal %d\n", sig);
struct sigaction act;
act.sa_handler = SIG_DFL;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
sigaction(sig, &act, 0);
sigprocmask(SIG_UNBLOCK, &previous_set, NULL);
exit(1);
}
void installSignalHandlers()
{
struct sigaction act;
act.sa_handler = handler;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
//Aparently these are terminal signals
sigaction(SIGINT, &act, 0);
sigaction(SIGFPE, &act, 0);
sigaction(SIGQUIT, &act, 0);
sigaction(SIGSEGV, &act, 0);
sigaction(SIGHUP, &act, 0);
sigaction(SIGABRT, &act, 0);
sigaction(SIGKILL, &act, 0);
}