2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-09-05 08:45:28 +00:00

Use sigabbrev_np(3) to access signal abbreviations if supported.

glibc-2.32 has removed sys_sigabbrev[], we can use sigabbrev_np(3) instead.
This commit is contained in:
Todd C. Miller
2020-08-25 16:48:13 -06:00
parent 3235687d96
commit 019f1f6b93
5 changed files with 100 additions and 71 deletions

View File

@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: ISC
*
* Copyright (c) 2012-2015, 2017-2019 Todd C. Miller <Todd.Miller@sudo.ws>
* Copyright (c) 2012-2015, 2017-2020 Todd C. Miller <Todd.Miller@sudo.ws>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -32,20 +32,24 @@
#include <unistd.h>
#include "sudo_compat.h"
#include "sudo_util.h"
#if defined(HAVE_DECL_SYS_SIGNAME) && HAVE_DECL_SYS_SIGNAME == 1
# define sudo_sys_signame sys_signame
#elif defined(HAVE_DECL__SYS_SIGNAME) && HAVE_DECL__SYS_SIGNAME == 1
# define sudo_sys_signame _sys_signame
#elif defined(HAVE_DECL_SYS_SIGABBREV) && HAVE_DECL_SYS_SIGABBREV == 1
# define sudo_sys_signame sys_sigabbrev
#else
# ifdef HAVE_SYS_SIGABBREV
/* sys_sigabbrev is not declared by glibc */
# define sudo_sys_signame sys_sigabbrev
#if !defined(HAVE_SIGABBREV_NP)
# if defined(HAVE_DECL_SYS_SIGNAME) && HAVE_DECL_SYS_SIGNAME == 1
# define sigabbrev_np(_x) sys_signame[(_x)]
# elif defined(HAVE_DECL__SYS_SIGNAME) && HAVE_DECL__SYS_SIGNAME == 1
# define sigabbrev_np(_x) _sys_signame[(_x)]
# elif defined(HAVE_SYS_SIGABBREV)
# define sigabbrev_np(_x) sys_sigabbrev[(_x)]
# if defined(HAVE_DECL_SYS_SIGABBREV) && HAVE_DECL_SYS_SIGABBREV == 0
/* sys_sigabbrev is not declared by glibc */
extern const char *const sys_sigabbrev[NSIG];
# endif
# else
# define sigabbrev_np(_x) sudo_sys_signame[(_x)]
extern const char *const sudo_sys_signame[NSIG];
# endif
extern const char *const sudo_sys_signame[NSIG];
#endif
#endif /* !HAVE_SIGABBREV_NP */
/*
* Translate signal number to name.
@@ -77,15 +81,18 @@ sudo_sig2str(int signo, char *signame)
return 0;
}
#endif
if (signo > 0 && signo < NSIG && sudo_sys_signame[signo] != NULL) {
strlcpy(signame, sudo_sys_signame[signo], SIG2STR_MAX);
/* Make sure we always return an upper case signame. */
if (islower((unsigned char)signame[0])) {
int i;
for (i = 0; signame[i] != '\0'; i++)
signame[i] = toupper((unsigned char)signame[i]);
if (signo > 0 && signo < NSIG) {
const char *cp = sigabbrev_np(signo);
if (cp != NULL) {
strlcpy(signame, cp, SIG2STR_MAX);
/* Make sure we always return an upper case signame. */
if (islower((unsigned char)signame[0])) {
int i;
for (i = 0; signame[i] != '\0'; i++)
signame[i] = toupper((unsigned char)signame[i]);
}
return 0;
}
return 0;
}
errno = EINVAL;
return -1;