-
Notifications
You must be signed in to change notification settings - Fork 0
/
getsignal.c
98 lines (94 loc) · 1.61 KB
/
getsignal.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
87
88
89
90
91
92
93
94
95
96
97
98
/* getsignal - associates signal names and signal numbers */
#include <errno.h>
#include <limits.h>
#include <signal.h>
#include <stdlib.h>
#include <strings.h>
#include "getsignal.h"
#include "util.h"
const Getsignal getsignals[] = {
{SIGABRT, "ABRT"},
{SIGALRM, "ALRM"},
{SIGBUS, "BUS"},
{SIGCHLD, "CHLD"},
#ifdef SIGCLD
{SIGCLD, "CLD"},
#endif
{SIGCONT, "CONT"},
#ifdef SIGEMT
{SIGEMT, "EMT"},
#endif
{SIGFPE, "FPE"},
{SIGHUP, "HUP"},
{SIGILL, "ILL"},
#ifdef SIGINFO
{SIGINFO, "INFO"},
#endif
{SIGINT, "INT"},
#ifdef SIGIO
{SIGIO, "IO"},
#endif
#ifdef SIGIOT
{SIGIOT, "IOT"},
#endif
{SIGKILL, "KILL"},
#ifdef SIGLOST
{SIGLOST, "LOST"},
#endif
{SIGPIPE, "PIPE"},
#ifdef SIGPOLL
{SIGPOLL, "POLL"},
#endif
#ifdef SIGPROF
{SIGPROF, "PROF"},
#endif
#ifdef SIGPWR
{SIGPWR, "PWR"},
#endif
{SIGQUIT, "QUIT"},
{SIGSEGV, "SEGV"},
#ifdef SIGSTKFLT
{SIGSTKFLT, "STKFLT"},
#endif
{SIGSTOP, "STOP"},
#ifdef SIGSYS
{SIGSYS, "SYS"},
#endif
{SIGTERM, "TERM"},
{SIGTRAP, "TRAP"},
{SIGTSTP, "TSTP"},
{SIGTTIN, "TTIN"},
{SIGTTOU, "TTOU"},
#ifdef SIGUNUSED
{SIGUNUSED, "UNUSED"},
#endif
{SIGURG, "URG"},
{SIGUSR1, "USR1"},
{SIGUSR2, "USR2"},
#ifdef SIGVTALRM
{SIGVTALRM, "VTALRM"},
#endif
#ifdef SIGWINCH
{SIGWINCH, "WINCH"},
#endif
#ifdef SIGXCPU
{SIGXCPU, "XCPU"},
#endif
#ifdef SIGXFSZ
{SIGXFSZ, "XFSZ"},
#endif
{0}
};
int getsignal(const char *name) {
char *p = (char *)name;
int num = parseuint(&p, INT_MAX, 10);
if (*p) {
return num;
} else if (p != name) {
return 0;
}
for (const Getsignal *s = getsignals; s->num; ++s) {
if (strncasecmp(s->name, name, SIGNAMELEN) == 0) return s->num;
}
return 0;
}