ping, ping6: Use setitimer(2) instead of obsolete alarm(3)

Submitted by:	Ján Sučan <sucanjan@gmail.com>
Differential Revision:	https://reviews.freebsd.org/D22103
This commit is contained in:
asomers 2019-11-26 05:06:25 +00:00
parent 62ba5c5b47
commit af0de3ad92
2 changed files with 18 additions and 2 deletions

View File

@ -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;

View File

@ -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