xref: /freebsd/lib/libsysdecode/signal.c (revision 05248206f720394d95c2a7475429311df670a2e9)
1 /*-
2  * Copyright (c) 2016 John H. Baldwin <jhb@FreeBSD.org>
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  */
25 
26 #include <sys/cdefs.h>
27 #include <sys/param.h>
28 #include <signal.h>
29 #include <stdbool.h>
30 #include <stdio.h>
31 #include <sysdecode.h>
32 
33 static const char *signames[] = {
34 	[SIGHUP] = "SIGHUP",
35 	[SIGINT] = "SIGINT",
36 	[SIGQUIT] = "SIGQUIT",
37 	[SIGILL] = "SIGILL",
38 	[SIGTRAP] = "SIGTRAP",
39 	[SIGABRT] = "SIGABRT",
40 	[SIGEMT] = "SIGEMT",
41 	[SIGFPE] = "SIGFPE",
42 	[SIGKILL] = "SIGKILL",
43 	[SIGBUS] = "SIGBUS",
44 	[SIGSEGV] = "SIGSEGV",
45 	[SIGSYS] = "SIGSYS",
46 	[SIGPIPE] = "SIGPIPE",
47 	[SIGALRM] = "SIGALRM",
48 	[SIGTERM] = "SIGTERM",
49 	[SIGURG] = "SIGURG",
50 	[SIGSTOP] = "SIGSTOP",
51 	[SIGTSTP] = "SIGTSTP",
52 	[SIGCONT] = "SIGCONT",
53 	[SIGCHLD] = "SIGCHLD",
54 	[SIGTTIN] = "SIGTTIN",
55 	[SIGTTOU] = "SIGTTOU",
56 	[SIGIO] = "SIGIO",
57 	[SIGXCPU] = "SIGXCPU",
58 	[SIGXFSZ] = "SIGXFSZ",
59 	[SIGVTALRM] = "SIGVTALRM",
60 	[SIGPROF] = "SIGPROF",
61 	[SIGWINCH] = "SIGWINCH",
62 	[SIGINFO] = "SIGINFO",
63 	[SIGUSR1] = "SIGUSR1",
64 	[SIGUSR2] = "SIGUSR2",
65 	[SIGTHR] = "SIGTHR",
66 	[SIGLIBRT] = "SIGLIBRT",
67 
68 	/* XXX: Solaris uses SIGRTMIN, SIGRTMIN+<x>...SIGRTMAX-<x>, SIGRTMAX */
69 	[SIGRTMIN] = "SIGRT0",
70 	[SIGRTMIN + 1] = "SIGRT1",
71 	[SIGRTMIN + 2] = "SIGRT2",
72 	[SIGRTMIN + 3] = "SIGRT3",
73 	[SIGRTMIN + 4] = "SIGRT4",
74 	[SIGRTMIN + 5] = "SIGRT5",
75 	[SIGRTMIN + 6] = "SIGRT6",
76 	[SIGRTMIN + 7] = "SIGRT7",
77 	[SIGRTMIN + 8] = "SIGRT8",
78 	[SIGRTMIN + 9] = "SIGRT9",
79 	[SIGRTMIN + 10] = "SIGRT10",
80 	[SIGRTMIN + 11] = "SIGRT11",
81 	[SIGRTMIN + 12] = "SIGRT12",
82 	[SIGRTMIN + 13] = "SIGRT13",
83 	[SIGRTMIN + 14] = "SIGRT14",
84 	[SIGRTMIN + 15] = "SIGRT15",
85 	[SIGRTMIN + 16] = "SIGRT16",
86 	[SIGRTMIN + 17] = "SIGRT17",
87 	[SIGRTMIN + 18] = "SIGRT18",
88 	[SIGRTMIN + 19] = "SIGRT19",
89 	[SIGRTMIN + 20] = "SIGRT20",
90 	[SIGRTMIN + 21] = "SIGRT21",
91 	[SIGRTMIN + 22] = "SIGRT22",
92 	[SIGRTMIN + 23] = "SIGRT23",
93 	[SIGRTMIN + 24] = "SIGRT24",
94 	[SIGRTMIN + 25] = "SIGRT25",
95 	[SIGRTMIN + 26] = "SIGRT26",
96 	[SIGRTMIN + 27] = "SIGRT27",
97 	[SIGRTMIN + 28] = "SIGRT28",
98 	[SIGRTMIN + 29] = "SIGRT29",
99 	[SIGRTMIN + 30] = "SIGRT30",
100 	[SIGRTMIN + 31] = "SIGRT31",
101 	[SIGRTMIN + 32] = "SIGRT32",
102 	[SIGRTMIN + 33] = "SIGRT33",
103 	[SIGRTMIN + 34] = "SIGRT34",
104 	[SIGRTMIN + 35] = "SIGRT35",
105 	[SIGRTMIN + 36] = "SIGRT36",
106 	[SIGRTMIN + 37] = "SIGRT37",
107 	[SIGRTMIN + 38] = "SIGRT38",
108 	[SIGRTMIN + 39] = "SIGRT39",
109 	[SIGRTMIN + 40] = "SIGRT40",
110 	[SIGRTMIN + 41] = "SIGRT41",
111 	[SIGRTMIN + 42] = "SIGRT42",
112 	[SIGRTMIN + 43] = "SIGRT43",
113 	[SIGRTMIN + 44] = "SIGRT44",
114 	[SIGRTMIN + 45] = "SIGRT45",
115 	[SIGRTMIN + 46] = "SIGRT46",
116 	[SIGRTMIN + 47] = "SIGRT47",
117 	[SIGRTMIN + 48] = "SIGRT48",
118 	[SIGRTMIN + 49] = "SIGRT49",
119 	[SIGRTMIN + 50] = "SIGRT50",
120 	[SIGRTMIN + 51] = "SIGRT51",
121 	[SIGRTMIN + 52] = "SIGRT52",
122 	[SIGRTMIN + 53] = "SIGRT53",
123 	[SIGRTMIN + 54] = "SIGRT54",
124 	[SIGRTMIN + 55] = "SIGRT55",
125 	[SIGRTMIN + 56] = "SIGRT56",
126 	[SIGRTMIN + 57] = "SIGRT57",
127 	[SIGRTMIN + 58] = "SIGRT58",
128 	[SIGRTMIN + 59] = "SIGRT59",
129 	[SIGRTMIN + 60] = "SIGRT60",
130 	[SIGRTMIN + 61] = "SIGRT61",
131 };
132 
133 const char *
134 sysdecode_signal(int sig)
135 {
136 
137 	if ((unsigned)sig < nitems(signames))
138 		return (signames[sig]);
139 	return (NULL);
140 }
141