iputils/backport-ping-Handle-interval-correctly-in-the-second-after-booting.patch
2025-02-13 06:19:15 +00:00

37 lines
1.3 KiB
Diff

From 7448c33af407636e66ac90deb828764df51835d4 Mon Sep 17 00:00:00 2001
From: Josh Triplett <josh@joshtriplett.org>
Date: Mon, 20 Nov 2023 19:09:06 -0800
Subject: [PATCH] ping: Handle interval correctly in the second after booting
ping assumes that if a timespec has tv_sec == 0, it hasn't been
initialized yet. However, in the second after booting up, tv_sec will
legitimately be 0. This causes ping to send pings one after another
without waiting.
Check that tv_nsec is 0 as well.
Link: https://github.com/iputils/iputils/pull/499
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Tested-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Josh Triplett <josh@joshtriplett.org>
Conflict:NA
Reference:https://github.com/iputils/iputils/commit/7448c33af407636e66ac90deb828764df51835d4
---
ping/ping_common.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ping/ping_common.c b/ping/ping_common.c
index c8b868b7..5a6c35aa 100644
--- a/ping/ping_common.c
+++ b/ping/ping_common.c
@@ -321,7 +321,7 @@ int pinger(struct ping_rts *rts, ping_func_set_st *fset, socket_st *sock)
return 1000;
/* Check that packets < rate*time + preload */
- if (rts->cur_time.tv_sec == 0) {
+ if (rts->cur_time.tv_sec == 0 && rts->cur_time.tv_nsec == 0) {
clock_gettime(CLOCK_MONOTONIC_RAW, &rts->cur_time);
tokens = rts->interval * (rts->preload - 1);
} else {