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

@@ -740,6 +740,9 @@
/* Define to 1 if you have the `sig2str' function. */
#undef HAVE_SIG2STR
/* Define to 1 if you have the `sigabbrev_np' function. */
#undef HAVE_SIGABBREV_NP
/* Define to 1 if you use S/Key. */
#undef HAVE_SKEY

39
configure vendored
View File

@@ -23687,9 +23687,21 @@ done
if test x"${ac_cv_func_sig2str}${ac_cv_func_str2sig}" != x"yesyes"; then
COMPAT_TEST_PROGS="${COMPAT_TEST_PROGS}${COMPAT_TEST_PROGS+ }strsig_test"
HAVE_SIGNAME="false"
ac_fn_c_check_decl "$LINENO" "sys_signame" "ac_cv_have_decl_sys_signame" "
for ac_func in sigabbrev_np
do :
ac_fn_c_check_func "$LINENO" "sigabbrev_np" "ac_cv_func_sigabbrev_np"
if test "x$ac_cv_func_sigabbrev_np" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_SIGABBREV_NP 1
_ACEOF
fi
done
if test x"${ac_cv_func_sigabbrev_np}" != x"yes"; then
COMPAT_TEST_PROGS="${COMPAT_TEST_PROGS}${COMPAT_TEST_PROGS+ }strsig_test"
HAVE_SIGNAME="false"
ac_fn_c_check_decl "$LINENO" "sys_signame" "ac_cv_have_decl_sys_signame" "
$ac_includes_default
#include <signal.h>
@@ -23705,7 +23717,7 @@ cat >>confdefs.h <<_ACEOF
_ACEOF
if test $ac_have_decl = 1; then :
HAVE_SIGNAME="true"
HAVE_SIGNAME="true"
fi
ac_fn_c_check_decl "$LINENO" "_sys_signame" "ac_cv_have_decl__sys_signame" "
@@ -23724,7 +23736,7 @@ cat >>confdefs.h <<_ACEOF
_ACEOF
if test $ac_have_decl = 1; then :
HAVE_SIGNAME="true"
HAVE_SIGNAME="true"
fi
ac_fn_c_check_decl "$LINENO" "sys_sigabbrev" "ac_cv_have_decl_sys_sigabbrev" "
@@ -23743,12 +23755,12 @@ cat >>confdefs.h <<_ACEOF
_ACEOF
if test $ac_have_decl = 1; then :
HAVE_SIGNAME="true"
HAVE_SIGNAME="true"
fi
if test "$HAVE_SIGNAME" != "true"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for undeclared sys_sigabbrev" >&5
if test "$HAVE_SIGNAME" != "true"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for undeclared sys_sigabbrev" >&5
$as_echo_n "checking for undeclared sys_sigabbrev... " >&6; }
if ${sudo_cv_var_sys_sigabbrev+:} false; then :
$as_echo_n "(cached) " >&6
@@ -23777,17 +23789,18 @@ rm -f core conftest.err conftest.$ac_objext \
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $sudo_cv_var_sys_sigabbrev" >&5
$as_echo "$sudo_cv_var_sys_sigabbrev" >&6; }
if test "$sudo_cv_var_sys_sigabbrev" = yes; then
$as_echo "#define HAVE_SYS_SIGABBREV 1" >>confdefs.h
if test "$sudo_cv_var_sys_sigabbrev" = yes; then
$as_echo "#define HAVE_SYS_SIGABBREV 1" >>confdefs.h
else
case " $LIBOBJS " in
else
case " $LIBOBJS " in
*" signame.$ac_objext "* ) ;;
*) LIBOBJS="$LIBOBJS signame.$ac_objext"
;;
esac
SIGNAME=signame.lo
SIGNAME=signame.lo
fi
fi
fi
fi

View File

@@ -3498,29 +3498,32 @@ dnl Check for sys_signame or sys_sigabbrev if missing sig2str() or str2sig().
dnl Also enable unit tests for sig2str() and str2sig().
dnl
if test x"${ac_cv_func_sig2str}${ac_cv_func_str2sig}" != x"yesyes"; then
COMPAT_TEST_PROGS="${COMPAT_TEST_PROGS}${COMPAT_TEST_PROGS+ }strsig_test"
HAVE_SIGNAME="false"
AC_CHECK_DECLS([sys_signame, _sys_signame, sys_sigabbrev], [
HAVE_SIGNAME="true"
], [ ], [
AC_CHECK_FUNCS([sigabbrev_np])
if test x"${ac_cv_func_sigabbrev_np}" != x"yes"; then
COMPAT_TEST_PROGS="${COMPAT_TEST_PROGS}${COMPAT_TEST_PROGS+ }strsig_test"
HAVE_SIGNAME="false"
AC_CHECK_DECLS([sys_signame, _sys_signame, sys_sigabbrev], [
HAVE_SIGNAME="true"
], [ ], [
AC_INCLUDES_DEFAULT
#include <signal.h>
])
if test "$HAVE_SIGNAME" != "true"; then
AC_CACHE_CHECK([for undeclared sys_sigabbrev],
[sudo_cv_var_sys_sigabbrev],
[AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[extern char **sys_sigabbrev;]], [[return sys_sigabbrev[1];]])],
[sudo_cv_var_sys_sigabbrev=yes],
[sudo_cv_var_sys_sigabbrev=no]
)
]
)
if test "$sudo_cv_var_sys_sigabbrev" = yes; then
AC_DEFINE(HAVE_SYS_SIGABBREV)
else
AC_LIBOBJ(signame)
SIGNAME=signame.lo
])
if test "$HAVE_SIGNAME" != "true"; then
AC_CACHE_CHECK([for undeclared sys_sigabbrev],
[sudo_cv_var_sys_sigabbrev],
[AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[extern char **sys_sigabbrev;]], [[return sys_sigabbrev[1];]])],
[sudo_cv_var_sys_sigabbrev=yes],
[sudo_cv_var_sys_sigabbrev=no]
)
]
)
if test "$sudo_cv_var_sys_sigabbrev" = yes; then
AC_DEFINE(HAVE_SYS_SIGABBREV)
else
AC_LIBOBJ(signame)
SIGNAME=signame.lo
fi
fi
fi
fi

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;

View File

@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: ISC
*
* Copyright (c) 2019 Todd C. Miller <Todd.Miller@sudo.ws>
* Copyright (c) 2019-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
@@ -37,19 +37,22 @@
#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 */
/*
* Many systems use aliases for source backward compatibility.
@@ -154,11 +157,11 @@ sudo_str2sig(const char *signame, int *result)
}
}
/* Check sys_signame[]. */
for (signo = 1; signo < NSIG; signo++) {
if (sudo_sys_signame[signo] != NULL) {
const char *cp = sigabbrev_np(signo);
if (cp != NULL) {
/* On macOS sys_signame[] may contain lower-case names. */
if (strcasecmp(signame, sudo_sys_signame[signo]) == 0) {
if (strcasecmp(signame, cp) == 0) {
*result = signo;
return 0;
}