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