use sigaction when possible

pull/194/head
David van Leusen 4 years ago
parent 69f7277076
commit 254573f241

@ -73,6 +73,10 @@ AC_CHECK_FUNC(connect)
if test $ac_cv_func_connect = no; then
AC_CHECK_LIB(socket, connect)
fi
AC_CHECK_FUNC(sigaction)
if test $ac_cv_func_sigaction = yes; then
AC_DEFINE([USE_SIGACTION],[1],[Define if sigaction is available.])
fi
AH_TOP([
#ifndef CONFIG_H

@ -434,6 +434,9 @@ int main(int argc, char** argv)
uid_t uid;
int tos = 0;
struct optparse optparse_state;
#ifdef USE_SIGACTION
struct sigaction act;
#endif
/* pre-parse -h/--help, so that we also can output help information
* without trying to open the socket, which might fail */
@ -1111,8 +1114,20 @@ int main(int argc, char** argv)
init_ping_buffer_ipv6(ping_data_size);
#endif
#ifdef USE_SIGACTION
memset(&act, 0, sizeof(act));
act.sa_handler = signal_handler;
sigemptyset(&act.sa_mask);
sigaddset(&act.sa_mask, SIGINT);
sigaddset(&act.sa_mask, SIGQUIT);
act.sa_flags = SA_RESTART;
if (sigaction(SIGQUIT, &act, NULL) || sigaction(SIGINT, &act, NULL)) {
crash_and_burn("failure to set signal handler");
}
#else
signal(SIGINT, signal_handler);
signal(SIGQUIT, signal_handler);
#endif
setlinebuf(stdout);
if (report_interval) {

Loading…
Cancel
Save