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