diff --git a/configure.ac b/configure.ac index 764e958..c7df87a 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/src/fping.c b/src/fping.c index 327266a..1efd4f8 100644 --- a/src/fping.c +++ b/src/fping.c @@ -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) {