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. */ /* Define to 1 if you have the `sig2str' function. */
#undef HAVE_SIG2STR #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. */ /* Define to 1 if you use S/Key. */
#undef HAVE_SKEY #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 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" for ac_func in sigabbrev_np
HAVE_SIGNAME="false" do :
ac_fn_c_check_decl "$LINENO" "sys_signame" "ac_cv_have_decl_sys_signame" " 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 $ac_includes_default
#include <signal.h> #include <signal.h>
@@ -23705,7 +23717,7 @@ cat >>confdefs.h <<_ACEOF
_ACEOF _ACEOF
if test $ac_have_decl = 1; then : if test $ac_have_decl = 1; then :
HAVE_SIGNAME="true" HAVE_SIGNAME="true"
fi fi
ac_fn_c_check_decl "$LINENO" "_sys_signame" "ac_cv_have_decl__sys_signame" " ac_fn_c_check_decl "$LINENO" "_sys_signame" "ac_cv_have_decl__sys_signame" "
@@ -23724,7 +23736,7 @@ cat >>confdefs.h <<_ACEOF
_ACEOF _ACEOF
if test $ac_have_decl = 1; then : if test $ac_have_decl = 1; then :
HAVE_SIGNAME="true" HAVE_SIGNAME="true"
fi fi
ac_fn_c_check_decl "$LINENO" "sys_sigabbrev" "ac_cv_have_decl_sys_sigabbrev" " ac_fn_c_check_decl "$LINENO" "sys_sigabbrev" "ac_cv_have_decl_sys_sigabbrev" "
@@ -23743,12 +23755,12 @@ cat >>confdefs.h <<_ACEOF
_ACEOF _ACEOF
if test $ac_have_decl = 1; then : if test $ac_have_decl = 1; then :
HAVE_SIGNAME="true" HAVE_SIGNAME="true"
fi fi
if test "$HAVE_SIGNAME" != "true"; then if test "$HAVE_SIGNAME" != "true"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for undeclared sys_sigabbrev" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for undeclared sys_sigabbrev" >&5
$as_echo_n "checking for undeclared sys_sigabbrev... " >&6; } $as_echo_n "checking for undeclared sys_sigabbrev... " >&6; }
if ${sudo_cv_var_sys_sigabbrev+:} false; then : if ${sudo_cv_var_sys_sigabbrev+:} false; then :
$as_echo_n "(cached) " >&6 $as_echo_n "(cached) " >&6
@@ -23777,17 +23789,18 @@ rm -f core conftest.err conftest.$ac_objext \
fi fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $sudo_cv_var_sys_sigabbrev" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $sudo_cv_var_sys_sigabbrev" >&5
$as_echo "$sudo_cv_var_sys_sigabbrev" >&6; } $as_echo "$sudo_cv_var_sys_sigabbrev" >&6; }
if test "$sudo_cv_var_sys_sigabbrev" = yes; then if test "$sudo_cv_var_sys_sigabbrev" = yes; then
$as_echo "#define HAVE_SYS_SIGABBREV 1" >>confdefs.h $as_echo "#define HAVE_SYS_SIGABBREV 1" >>confdefs.h
else else
case " $LIBOBJS " in case " $LIBOBJS " in
*" signame.$ac_objext "* ) ;; *" signame.$ac_objext "* ) ;;
*) LIBOBJS="$LIBOBJS signame.$ac_objext" *) LIBOBJS="$LIBOBJS signame.$ac_objext"
;; ;;
esac esac
SIGNAME=signame.lo SIGNAME=signame.lo
fi
fi fi
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 Also enable unit tests for sig2str() and str2sig().
dnl dnl
if test x"${ac_cv_func_sig2str}${ac_cv_func_str2sig}" != x"yesyes"; then 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" AC_CHECK_FUNCS([sigabbrev_np])
HAVE_SIGNAME="false" if test x"${ac_cv_func_sigabbrev_np}" != x"yes"; then
AC_CHECK_DECLS([sys_signame, _sys_signame, sys_sigabbrev], [ COMPAT_TEST_PROGS="${COMPAT_TEST_PROGS}${COMPAT_TEST_PROGS+ }strsig_test"
HAVE_SIGNAME="true" HAVE_SIGNAME="false"
], [ ], [ AC_CHECK_DECLS([sys_signame, _sys_signame, sys_sigabbrev], [
HAVE_SIGNAME="true"
], [ ], [
AC_INCLUDES_DEFAULT AC_INCLUDES_DEFAULT
#include <signal.h> #include <signal.h>
]) ])
if test "$HAVE_SIGNAME" != "true"; then if test "$HAVE_SIGNAME" != "true"; then
AC_CACHE_CHECK([for undeclared sys_sigabbrev], AC_CACHE_CHECK([for undeclared sys_sigabbrev],
[sudo_cv_var_sys_sigabbrev], [sudo_cv_var_sys_sigabbrev],
[AC_LINK_IFELSE( [AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[extern char **sys_sigabbrev;]], [[return sys_sigabbrev[1];]])], [AC_LANG_PROGRAM([[extern char **sys_sigabbrev;]], [[return sys_sigabbrev[1];]])],
[sudo_cv_var_sys_sigabbrev=yes], [sudo_cv_var_sys_sigabbrev=yes],
[sudo_cv_var_sys_sigabbrev=no] [sudo_cv_var_sys_sigabbrev=no]
) )
] ]
) )
if test "$sudo_cv_var_sys_sigabbrev" = yes; then if test "$sudo_cv_var_sys_sigabbrev" = yes; then
AC_DEFINE(HAVE_SYS_SIGABBREV) AC_DEFINE(HAVE_SYS_SIGABBREV)
else else
AC_LIBOBJ(signame) AC_LIBOBJ(signame)
SIGNAME=signame.lo SIGNAME=signame.lo
fi
fi fi
fi fi
fi fi

View File

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

View File

@@ -1,7 +1,7 @@
/* /*
* SPDX-License-Identifier: ISC * 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 * Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@@ -37,19 +37,22 @@
#include "sudo_compat.h" #include "sudo_compat.h"
#include "sudo_util.h" #include "sudo_util.h"
#if defined(HAVE_DECL_SYS_SIGNAME) && HAVE_DECL_SYS_SIGNAME == 1 #if !defined(HAVE_SIGABBREV_NP)
# define sudo_sys_signame sys_signame # if defined(HAVE_DECL_SYS_SIGNAME) && HAVE_DECL_SYS_SIGNAME == 1
#elif defined(HAVE_DECL__SYS_SIGNAME) && HAVE_DECL__SYS_SIGNAME == 1 # define sigabbrev_np(_x) sys_signame[(_x)]
# define sudo_sys_signame _sys_signame # elif defined(HAVE_DECL__SYS_SIGNAME) && HAVE_DECL__SYS_SIGNAME == 1
#elif defined(HAVE_DECL_SYS_SIGABBREV) && HAVE_DECL_SYS_SIGABBREV == 1 # define sigabbrev_np(_x) _sys_signame[(_x)]
# define sudo_sys_signame sys_sigabbrev # elif defined(HAVE_SYS_SIGABBREV)
#else # define sigabbrev_np(_x) sys_sigabbrev[(_x)]
# ifdef HAVE_SYS_SIGABBREV # if defined(HAVE_DECL_SYS_SIGABBREV) && HAVE_DECL_SYS_SIGABBREV == 0
/* sys_sigabbrev is not declared by glibc */ /* sys_sigabbrev is not declared by glibc */
# define sudo_sys_signame sys_sigabbrev 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 # endif
extern const char *const sudo_sys_signame[NSIG]; #endif /* !HAVE_SIGABBREV_NP */
#endif
/* /*
* Many systems use aliases for source backward compatibility. * 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++) { 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. */ /* On macOS sys_signame[] may contain lower-case names. */
if (strcasecmp(signame, sudo_sys_signame[signo]) == 0) { if (strcasecmp(signame, cp) == 0) {
*result = signo; *result = signo;
return 0; return 0;
} }