diff --git a/configure.ac b/configure.ac index f389ac3..67c1f18 100644 --- a/configure.ac +++ b/configure.ac @@ -60,6 +60,43 @@ AC_TYPE_SIZE_T AC_TYPE_SSIZE_T AC_TYPE_UID_T +dnl Check that a signal handler can't see the PID of the sender. +AC_MSG_CHECKING([siginfo_t provides a signal sender's PID]) +AC_RUN_IFELSE( +[AC_LANG_PROGRAM([[ +#include +#include +#include + +static pid_t signalSender = 0; + +#ifdef SA_SIGINFO +static void receiveUSR2( __attribute__((unused)) + int sig, siginfo_t * info, __attribute__((unused)) + void *ucontext) +{ + if (NULL != info) + signalSender = info->si_pid; +} +#endif +]], [[ + struct sigaction sa; + memset(&sa, 0, sizeof(sa)); +#ifdef SA_SIGINFO + sa.sa_sigaction = receiveUSR2; + (void) sigemptyset(&(sa.sa_mask)); + sa.sa_flags = SA_SIGINFO; + (void) sigaction(SIGUSR2, &sa, NULL); + raise(SIGUSR2); +#endif + return signalSender == 0 ? 1 : 0; +]])], [ +AC_MSG_RESULT([yes]) +AC_DEFINE([SIGINFO_PROVIDES_PID], [1], [Signal handlers can determine the sending PID]) +], [ +AC_MSG_RESULT([no]) +]) + AH_BOTTOM([#include "config-aux.h"]) AC_ARG_ENABLE([debugging], diff --git a/src/include/config.h.in b/src/include/config.h.in index 5ba8d90..99b33cc 100644 --- a/src/include/config.h.in +++ b/src/include/config.h.in @@ -223,6 +223,9 @@ /* Define to the version of this package. */ #undef PACKAGE_VERSION +/* Signal handlers can determine the sending PID */ +#undef SIGINFO_PROVIDES_PID + /* Define to 1 if all of the C90 standard headers exist (not just the ones required in a freestanding environment). This macro is provided for backward compatibility; new code need not use it. */ diff --git a/src/include/pv-internal.h b/src/include/pv-internal.h index 720d275..b0cf7b2 100644 --- a/src/include/pv-internal.h +++ b/src/include/pv-internal.h @@ -154,13 +154,13 @@ struct pvstate_s { struct sigaction old_sigint; struct sigaction old_sighup; struct sigaction old_sigterm; -#ifdef SA_SIGINFO +#ifdef SIGINFO_PROVIDES_PID struct sigaction old_sigusr2; #endif struct sigaction old_sigalrm; struct timespec tstp_time; /* see pv_sig_tstp() / __cont() */ struct timespec toffset; /* total time spent stopped */ -#ifdef SA_SIGINFO +#ifdef SIGINFO_PROVIDES_PID volatile sig_atomic_t rxusr2; /* whether SIGUSR2 was received */ volatile pid_t sender; /* PID of sending process for SIGUSR2 */ #endif diff --git a/src/include/pv.h b/src/include/pv.h index 5a744cf..abd0812 100644 --- a/src/include/pv.h +++ b/src/include/pv.h @@ -237,7 +237,7 @@ extern off_t pv_calc_total_size(pvstate_t); */ extern void pv_sig_init(pvstate_t); -#ifdef SA_SIGINFO +#ifdef SIGINFO_PROVIDES_PID /* * Return true if SIGUSR2 has been received, and indicate the sender. */ diff --git a/src/main/help.c b/src/main/help.c index e05ee4b..1a7c530 100644 --- a/src/main/help.c +++ b/src/main/help.c @@ -399,11 +399,11 @@ void display_help(void) { "-U", "--store-and-forward", N_("FILE"), N_("write all input to FILE before writing to output"), { 0, 0, 0, 0} }, -#ifdef SA_SIGINFO +#ifdef SIGINFO_PROVIDES_PID { "-R", "--remote", N_("PID"), N_("update settings of process PID"), { 0, 0, 0, 0} }, -#endif /* SA_SIGINFO */ +#endif /* SIGINFO_PROVIDES_PID */ { "", NULL, NULL, NULL, { 0, 0, 0, 0} }, { "-P", "--pidfile", N_("FILE"), N_("save process ID in FILE"), diff --git a/src/main/remote.c b/src/main/remote.c index 5747995..d71a2ae 100644 --- a/src/main/remote.c +++ b/src/main/remote.c @@ -21,7 +21,7 @@ #include #include -#ifdef SA_SIGINFO +#ifdef SIGINFO_PROVIDES_PID void pv_error(pvstate_t, char *, ...); struct remote_msg { @@ -405,10 +405,10 @@ void pv_remote_fini(void) { } -#else /* !SA_SIGINFO */ +#else /* !SIGINFO_PROVIDES_PID */ /* - * Dummy stubs for remote control when we don't have SA_SIGINFO. + * Dummy stubs for remote control when we don't have SIGINFO_PROVIDES_PID. */ void pv_remote_init(void) { diff --git a/src/pv/signal.c b/src/pv/signal.c index 78af20b..93cf808 100644 --- a/src/pv/signal.c +++ b/src/pv/signal.c @@ -226,7 +226,7 @@ static void pv_sig_term( /*@unused@ */ __attribute__((unused)) } -#ifdef SA_SIGINFO +#ifdef SIGINFO_PROVIDES_PID /* * Handle a SIGUSR2 by setting a flag to say we received it, after recording * the sending PID. @@ -375,7 +375,7 @@ void pv_sig_init(pvstate_t state) sa.sa_flags = 0; (void) sigaction(SIGTERM, &sa, &(pv_sig_state->signal.old_sigterm)); -#ifdef SA_SIGINFO +#ifdef SIGINFO_PROVIDES_PID /* * Handle SIGUSR2 by setting a flag to say the signal has been * received, and storing the sending process's PID. @@ -431,7 +431,7 @@ void pv_sig_fini( /*@unused@ */ __attribute__((unused)) pvstate_t state) (void) sigaction(SIGINT, &(pv_sig_state->signal.old_sigint), NULL); (void) sigaction(SIGHUP, &(pv_sig_state->signal.old_sighup), NULL); (void) sigaction(SIGTERM, &(pv_sig_state->signal.old_sigterm), NULL); -#ifdef SA_SIGINFO +#ifdef SIGINFO_PROVIDES_PID (void) sigaction(SIGUSR2, &(pv_sig_state->signal.old_sigusr2), NULL); #endif (void) sigaction(SIGALRM, &(pv_sig_state->signal.old_sigalrm), NULL);