]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - lib/signames.c
2 * Copyright (c) 1988, 1993, 1994, 2017
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * 2017-10-14 Niklas Hambüchen <mail@nh2.me>
35 * - Extracted signal names mapping from kill.c
37 * Copyright (C) 2014 Sami Kerola <kerolasa@iki.fi>
38 * Copyright (C) 2014 Karel Zak <kzak@redhat.com>
39 * Copyright (C) 2017 Niklas Hambüchen <mail@nh2.me>
42 #include <ctype.h> /* for isdigit() */
52 static const struct ul_signal_name
{
57 { "HUP", SIGHUP
}, /* 1 */
58 { "INT", SIGINT
}, /* 2 */
59 { "QUIT", SIGQUIT
}, /* 3 */
60 { "ILL", SIGILL
}, /* 4 */
62 { "TRAP", SIGTRAP
}, /* 5 */
64 { "ABRT", SIGABRT
}, /* 6 */
66 { "IOT", SIGIOT
}, /* 6, same as SIGABRT */
69 { "EMT", SIGEMT
}, /* 7 (mips,alpha,sparc*) */
72 { "BUS", SIGBUS
}, /* 7 (arm,i386,m68k,ppc), 10 (mips,alpha,sparc*) */
74 { "FPE", SIGFPE
}, /* 8 */
75 { "KILL", SIGKILL
}, /* 9 */
76 { "USR1", SIGUSR1
}, /* 10 (arm,i386,m68k,ppc), 30 (alpha,sparc*), 16 (mips) */
77 { "SEGV", SIGSEGV
}, /* 11 */
78 { "USR2", SIGUSR2
}, /* 12 (arm,i386,m68k,ppc), 31 (alpha,sparc*), 17 (mips) */
79 { "PIPE", SIGPIPE
}, /* 13 */
80 { "ALRM", SIGALRM
}, /* 14 */
81 { "TERM", SIGTERM
}, /* 15 */
83 { "STKFLT", SIGSTKFLT
}, /* 16 (arm,i386,m68k,ppc) */
85 { "CHLD", SIGCHLD
}, /* 17 (arm,i386,m68k,ppc), 20 (alpha,sparc*), 18 (mips) */
87 { "CLD", SIGCLD
}, /* same as SIGCHLD (mips) */
89 { "CONT", SIGCONT
}, /* 18 (arm,i386,m68k,ppc), 19 (alpha,sparc*), 25 (mips) */
90 { "STOP", SIGSTOP
}, /* 19 (arm,i386,m68k,ppc), 17 (alpha,sparc*), 23 (mips) */
91 { "TSTP", SIGTSTP
}, /* 20 (arm,i386,m68k,ppc), 18 (alpha,sparc*), 24 (mips) */
92 { "TTIN", SIGTTIN
}, /* 21 (arm,i386,m68k,ppc,alpha,sparc*), 26 (mips) */
93 { "TTOU", SIGTTOU
}, /* 22 (arm,i386,m68k,ppc,alpha,sparc*), 27 (mips) */
95 { "URG", SIGURG
}, /* 23 (arm,i386,m68k,ppc), 16 (alpha,sparc*), 21 (mips) */
98 { "XCPU", SIGXCPU
}, /* 24 (arm,i386,m68k,ppc,alpha,sparc*), 30 (mips) */
101 { "XFSZ", SIGXFSZ
}, /* 25 (arm,i386,m68k,ppc,alpha,sparc*), 31 (mips) */
104 { "VTALRM", SIGVTALRM
}, /* 26 (arm,i386,m68k,ppc,alpha,sparc*), 28 (mips) */
107 { "PROF", SIGPROF
}, /* 27 (arm,i386,m68k,ppc,alpha,sparc*), 29 (mips) */
110 { "WINCH", SIGWINCH
}, /* 28 (arm,i386,m68k,ppc,alpha,sparc*), 20 (mips) */
113 { "IO", SIGIO
}, /* 29 (arm,i386,m68k,ppc), 23 (alpha,sparc*), 22 (mips) */
116 { "POLL", SIGPOLL
}, /* same as SIGIO */
119 { "INFO", SIGINFO
}, /* 29 (alpha) */
122 { "LOST", SIGLOST
}, /* 29 (arm,i386,m68k,ppc,sparc*) */
125 { "PWR", SIGPWR
}, /* 30 (arm,i386,m68k,ppc), 29 (alpha,sparc*), 19 (mips) */
128 { "UNUSED", SIGUNUSED
}, /* 31 (arm,i386,m68k,ppc) */
131 { "SYS", SIGSYS
}, /* 31 (mips,alpha,sparc*) */
136 static int rtsig_to_signum(const char *sig
)
141 if (strncasecmp(sig
, "min+", 4) == 0)
143 else if (strncasecmp(sig
, "max-", 4) == 0) {
150 num
= strtol(sig
, &ep
, 10);
151 if (!ep
|| sig
== ep
|| errno
|| num
< 0)
153 num
= maxi
? SIGRTMAX
- num
: SIGRTMIN
+ num
;
154 if (num
< SIGRTMIN
|| SIGRTMAX
< num
)
160 int signame_to_signum(const char *sig
)
164 if (!strncasecmp(sig
, "sig", 3))
168 if (!strncasecmp(sig
, "rt", 2))
169 return rtsig_to_signum(sig
+ 2);
172 for (n
= 0; n
< ARRAY_SIZE(ul_signames
); n
++) {
173 if (!strcasecmp(ul_signames
[n
].name
, sig
))
174 return ul_signames
[n
].val
;
179 const char *signum_to_signame(int signum
)
183 for (n
= 0; n
< ARRAY_SIZE(ul_signames
); n
++) {
184 if (ul_signames
[n
].val
== signum
) {
185 return ul_signames
[n
].name
;
192 int get_signame_by_idx(size_t idx
, const char **signame
, int *signum
)
194 if (idx
>= ARRAY_SIZE(ul_signames
))
198 *signame
= ul_signames
[idx
].name
;
200 *signum
= ul_signames
[idx
].val
;