[git commit] ping: use setitimer() instead of ualarm()

Denys Vlasenko vda.linux at googlemail.com
Sat Aug 25 17:36:06 UTC 2018


commit: https://git.busybox.net/busybox/commit/?id=78a5ef9d2c034b5a6314fb66279160331d25cc73
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
sendping_tail                                        218     265     +47
ualarm                                                79       -     -79
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 1/0 up/down: 47/-79)            Total: -32 bytes

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 networking/ping.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/networking/ping.c b/networking/ping.c
index a579ea4ae..570184fee 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -485,9 +485,15 @@ static void sendping_tail(void (*sp)(int), int size_pkt)
 		bb_error_msg_and_die(bb_msg_write_error);
 
 	if (pingcount == 0 || G.ntransmitted < pingcount) {
-		/* Didn't send all pings yet - schedule next in 1s */
+		/* Didn't send all pings yet - schedule next in -i SEC interval */
+		struct itimerval i;
 		signal(SIGALRM, sp);
-		ualarm(G.interval_us, 0);
+		/*ualarm(G.interval_us, 0); - does not work for >=1sec on some libc */
+		i.it_interval.tv_sec = 0;
+		i.it_interval.tv_usec = 0;
+		i.it_value.tv_sec = G.interval_us / 1000000;
+		i.it_value.tv_usec = G.interval_us % 1000000;
+		setitimer(ITIMER_REAL, &i, NULL);
 	} else { /* -c NN, and all NN are sent */
 		/* Wait for the last ping to come back.
 		 * -W timeout: wait for a response in seconds.


More information about the busybox-cvs mailing list