xref: /freebsd/lib/libsysdecode/signal.c (revision 95eb4b873b6a8b527c5bd78d7191975dfca38998)
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/param.h>
27 #include <signal.h>
28 #include <stdbool.h>
29 #include <stdio.h>
30 #include <sysdecode.h>
31 
32 static const char *signames[] = {
33 	[SIGHUP] = "SIGHUP",
34 	[SIGINT] = "SIGINT",
35 	[SIGQUIT] = "SIGQUIT",
36 	[SIGILL] = "SIGILL",
37 	[SIGTRAP] = "SIGTRAP",
38 	[SIGABRT] = "SIGABRT",
39 	[SIGEMT] = "SIGEMT",
40 	[SIGFPE] = "SIGFPE",
41 	[SIGKILL] = "SIGKILL",
42 	[SIGBUS] = "SIGBUS",
43 	[SIGSEGV] = "SIGSEGV",
44 	[SIGSYS] = "SIGSYS",
45 	[SIGPIPE] = "SIGPIPE",
46 	[SIGALRM] = "SIGALRM",
47 	[SIGTERM] = "SIGTERM",
48 	[SIGURG] = "SIGURG",
49 	[SIGSTOP] = "SIGSTOP",
50 	[SIGTSTP] = "SIGTSTP",
51 	[SIGCONT] = "SIGCONT",
52 	[SIGCHLD] = "SIGCHLD",
53 	[SIGTTIN] = "SIGTTIN",
54 	[SIGTTOU] = "SIGTTOU",
55 	[SIGIO] = "SIGIO",
56 	[SIGXCPU] = "SIGXCPU",
57 	[SIGXFSZ] = "SIGXFSZ",
58 	[SIGVTALRM] = "SIGVTALRM",
59 	[SIGPROF] = "SIGPROF",
60 	[SIGWINCH] = "SIGWINCH",
61 	[SIGINFO] = "SIGINFO",
62 	[SIGUSR1] = "SIGUSR1",
63 	[SIGUSR2] = "SIGUSR2",
64 	[SIGTHR] = "SIGTHR",
65 	[SIGLIBRT] = "SIGLIBRT",
66 
67 	/* XXX: Solaris uses SIGRTMIN, SIGRTMIN+<x>...SIGRTMAX-<x>, SIGRTMAX */
68 	[SIGRTMIN] = "SIGRT0",
69 	[SIGRTMIN + 1] = "SIGRT1",
70 	[SIGRTMIN + 2] = "SIGRT2",
71 	[SIGRTMIN + 3] = "SIGRT3",
72 	[SIGRTMIN + 4] = "SIGRT4",
73 	[SIGRTMIN + 5] = "SIGRT5",
74 	[SIGRTMIN + 6] = "SIGRT6",
75 	[SIGRTMIN + 7] = "SIGRT7",
76 	[SIGRTMIN + 8] = "SIGRT8",
77 	[SIGRTMIN + 9] = "SIGRT9",
78 	[SIGRTMIN + 10] = "SIGRT10",
79 	[SIGRTMIN + 11] = "SIGRT11",
80 	[SIGRTMIN + 12] = "SIGRT12",
81 	[SIGRTMIN + 13] = "SIGRT13",
82 	[SIGRTMIN + 14] = "SIGRT14",
83 	[SIGRTMIN + 15] = "SIGRT15",
84 	[SIGRTMIN + 16] = "SIGRT16",
85 	[SIGRTMIN + 17] = "SIGRT17",
86 	[SIGRTMIN + 18] = "SIGRT18",
87 	[SIGRTMIN + 19] = "SIGRT19",
88 	[SIGRTMIN + 20] = "SIGRT20",
89 	[SIGRTMIN + 21] = "SIGRT21",
90 	[SIGRTMIN + 22] = "SIGRT22",
91 	[SIGRTMIN + 23] = "SIGRT23",
92 	[SIGRTMIN + 24] = "SIGRT24",
93 	[SIGRTMIN + 25] = "SIGRT25",
94 	[SIGRTMIN + 26] = "SIGRT26",
95 	[SIGRTMIN + 27] = "SIGRT27",
96 	[SIGRTMIN + 28] = "SIGRT28",
97 	[SIGRTMIN + 29] = "SIGRT29",
98 	[SIGRTMIN + 30] = "SIGRT30",
99 	[SIGRTMIN + 31] = "SIGRT31",
100 	[SIGRTMIN + 32] = "SIGRT32",
101 	[SIGRTMIN + 33] = "SIGRT33",
102 	[SIGRTMIN + 34] = "SIGRT34",
103 	[SIGRTMIN + 35] = "SIGRT35",
104 	[SIGRTMIN + 36] = "SIGRT36",
105 	[SIGRTMIN + 37] = "SIGRT37",
106 	[SIGRTMIN + 38] = "SIGRT38",
107 	[SIGRTMIN + 39] = "SIGRT39",
108 	[SIGRTMIN + 40] = "SIGRT40",
109 	[SIGRTMIN + 41] = "SIGRT41",
110 	[SIGRTMIN + 42] = "SIGRT42",
111 	[SIGRTMIN + 43] = "SIGRT43",
112 	[SIGRTMIN + 44] = "SIGRT44",
113 	[SIGRTMIN + 45] = "SIGRT45",
114 	[SIGRTMIN + 46] = "SIGRT46",
115 	[SIGRTMIN + 47] = "SIGRT47",
116 	[SIGRTMIN + 48] = "SIGRT48",
117 	[SIGRTMIN + 49] = "SIGRT49",
118 	[SIGRTMIN + 50] = "SIGRT50",
119 	[SIGRTMIN + 51] = "SIGRT51",
120 	[SIGRTMIN + 52] = "SIGRT52",
121 	[SIGRTMIN + 53] = "SIGRT53",
122 	[SIGRTMIN + 54] = "SIGRT54",
123 	[SIGRTMIN + 55] = "SIGRT55",
124 	[SIGRTMIN + 56] = "SIGRT56",
125 	[SIGRTMIN + 57] = "SIGRT57",
126 	[SIGRTMIN + 58] = "SIGRT58",
127 	[SIGRTMIN + 59] = "SIGRT59",
128 	[SIGRTMIN + 60] = "SIGRT60",
129 	[SIGRTMIN + 61] = "SIGRT61",
130 };
131 
132 const char *
133 sysdecode_signal(int sig)
134 {
135 
136 	if ((unsigned)sig < nitems(signames))
137 		return (signames[sig]);
138 	return (NULL);
139 }
140