-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignal.c
86 lines (79 loc) · 1.41 KB
/
signal.c
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "signal.h"
#include "util.h"
#include "forth.h"
#include <string.h>
#include <signal.h>
// register signal handlers.
void
forth_regist_sighandler(ForthInterp *interp, void (*handler)(int))
{
struct sigaction sa;
memset(&sa, 0, sizeof(struct sigaction));
// destruct_interp() traps all signals.
sa.sa_handler = handler;
sa.sa_flags |= SA_RESTART;
const int signals[] = {
#ifdef SIGABRT
SIGABRT,
#endif
#ifdef SIGALRM
SIGALRM,
#endif
#ifdef SIGBUS
SIGBUS,
#endif
#ifdef SIGFPE
SIGFPE,
#endif
#ifdef SIGHUP
SIGHUP,
#endif
#ifdef SIGILL
SIGILL,
#endif
#ifdef SIGINT
SIGINT,
#endif
#ifdef SIGIO
SIGIO,
#endif
#ifdef SIGPIPE
SIGPIPE,
#endif
#ifdef SIGPWR
SIGPWR,
#endif
#ifdef SIGQUIT
SIGQUIT,
#endif
#ifdef SIGSEGV
SIGSEGV,
#endif
#ifdef SIGSTKFLT
SIGSTKFLT,
#endif
#ifdef SIGTERM
SIGTERM,
#endif
#ifdef SIGSYS
SIGSYS,
#endif
#ifdef SIGVTALRM
SIGVTALRM,
#endif
#ifdef SIGXCPU
SIGXCPU,
#endif
#ifdef SIGXFSZ
SIGXFSZ,
#endif
};
const int len = sizeof(signals) / sizeof(int);
for (int i = 0; i < len; i++) {
if (sigaction(signals[i], &sa, NULL) != 0) {
// failed to register
forth_debugf(interp, "failed to register signal: %d: ", signals[i]);
forth_die(interp, "sigaction", FORTH_ERR_INIT);
}
}
}