From 2eb6acc2775b7c597f02907dc22fb839c4f229e3 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Tue, 26 Nov 2019 05:06:25 +0000 Subject: [PATCH] ping, ping6: Use setitimer(2) instead of obsolete alarm(3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Submitted by: Ján Sučan Differential Revision: https://reviews.freebsd.org/D22103 --- sbin/ping/ping.c | 10 +++++++++- sbin/ping6/ping6.c | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c index ebe97fb8e03a..011c77df816d 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -505,7 +505,15 @@ main(int argc, char *const *argv) if (alarmtimeout > MAXALARM) errx(EX_USAGE, "invalid timeout: `%s' > %d", optarg, MAXALARM); - alarm((int)alarmtimeout); + { + struct itimerval itv; + + timerclear(&itv.it_interval); + timerclear(&itv.it_value); + itv.it_value.tv_sec = (time_t)alarmtimeout; + if (setitimer(ITIMER_REAL, &itv, NULL) != 0) + err(1, "setitimer"); + } break; case 'v': options |= F_VERBOSE; diff --git a/sbin/ping6/ping6.c b/sbin/ping6/ping6.c index 5bd9de92545d..dd592f38e076 100644 --- a/sbin/ping6/ping6.c +++ b/sbin/ping6/ping6.c @@ -574,7 +574,15 @@ main(int argc, char *argv[]) if (alarmtimeout > MAXALARM) errx(EX_USAGE, "invalid timeout: `%s' > %d", optarg, MAXALARM); - alarm((int)alarmtimeout); + { + struct itimerval itv; + + timerclear(&itv.it_interval); + timerclear(&itv.it_value); + itv.it_value.tv_sec = (time_t)alarmtimeout; + if (setitimer(ITIMER_REAL, &itv, NULL) != 0) + err(1, "setitimer"); + } break; #ifdef IPSEC #ifdef IPSEC_POLICY_IPSEC