2 * Copyright (c) 2012 Todd C. Miller <Todd.Miller@courtesan.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/types.h>
30 #endif /* STDC_HEADERS */
33 #endif /* HAVE_STRING_H */
36 #endif /* HAVE_STRINGS_H */
41 #if defined(HAVE_DECL_SYS_SIGNAME) && HAVE_DECL_SYS_SIGNAME == 1
42 # define sudo_sys_signame sys_signame
43 #elif defined(HAVE_DECL__SYS_SIGNAME) && HAVE_DECL__SYS_SIGNAME == 1
44 # define sudo_sys_signame _sys_signame
45 #elif defined(HAVE_DECL___SYS_SIGNAME) && HAVE_DECL___SYS_SIGNAME == 1
46 # define sudo_sys_signame __sys_signame
47 #elif defined(HAVE_DECL_SYS_SIGABBREV) && HAVE_DECL_SYS_SIGABBREV == 1
48 # define sudo_sys_signame sys_sigabbrev
50 # ifdef HAVE_SYS_SIGABBREV
51 /* sys_sigabbrev is not declared by glibc */
52 # define sudo_sys_signame sys_sigabbrev
54 extern const char *const sudo_sys_signame[NSIG];
58 * Translate signal number to name.
61 sig2str(int signo, char *signame)
63 #if defined(SIGRTMIN) && defined(SIGRTMAX)
64 /* Realtime signal support as per Solaris. */
65 if (signo >= SIGRTMIN && signo <= SIGRTMAX) {
66 snprintf(signame, SIG2STR_MAX, "RTMIN+%d", (signo - SIGRTMIN));
70 if (signo > 0 && signo < NSIG && sudo_sys_signame[signo] != NULL) {
71 strlcpy(signame, sudo_sys_signame[signo], SIG2STR_MAX);