From 7c7e007502a3a2bd435a9e6b797387dbea8b992c Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Tue, 1 Nov 2016 11:42:12 +0100 Subject: [PATCH] - (bugfix) Lower -i limit to 1 instead of 10 - (bugfix) Improve interval preciseness of -Q reporting --- ChangeLog | 2 ++ doc/fping.pod | 4 ++-- src/fping.c | 25 +++++++++++++++++++------ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5d25ad4..4142cc2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,8 @@ UNRELEASED * (bugfix) Exit code should be 2 when the hostname can't be resolved (fixes #98, reported by @green-fox) * (bugfix) Fix issue compliling on RHEL/Centos 7 (#95, @jbackman) + * (bugfix) Lower -i limit to 1 instead of 10 + * (bugfix) Improve interval preciseness of -Q reporting 2015-10-21 David Schweikert * Version 3.13 diff --git a/doc/fping.pod b/doc/fping.pod index a193383..f0b8244 100644 --- a/doc/fping.pod +++ b/doc/fping.pod @@ -214,7 +214,7 @@ on the fly at one second intervals, and printing statistics at the end: # fping -s -l -i 1 -p 1 -T 1 -Q 1 127.0.0.1 -Note that ping intervals less than 10ms can only be used as root. +Note that ping intervals less than 1ms can only be used as root. =head1 AUTHORS @@ -257,7 +257,7 @@ to stop mere mortals from hosing the network, normal users can't specify the fol =item * -B<-i> I, where I < 10 msec +B<-i> I, where I < 1 msec =item * diff --git a/src/fping.c b/src/fping.c index 64abe77..1002518 100644 --- a/src/fping.c +++ b/src/fping.c @@ -128,7 +128,7 @@ extern int h_errno; /* maxima and minima */ #define MAX_COUNT 10000 -#define MIN_INTERVAL 10 /* in millisec */ +#define MIN_INTERVAL 1 /* in millisec */ #define MIN_PERHOST_INTERVAL 20 /* in millisec */ #define MIN_TIMEOUT 50 /* in millisec */ #define MAX_RETRY 20 @@ -290,7 +290,7 @@ struct timeval current_time; /* current time (pseudo) */ struct timeval start_time; struct timeval end_time; struct timeval last_send_time; /* time last ping was sent */ -struct timeval last_report_time; /* time last report was printed */ +struct timeval next_report_time; /* time next -Q report is expected */ struct timezone tz; /* switches */ @@ -846,8 +846,10 @@ int main( int argc, char **argv ) gettimeofday( &start_time, &tz ); current_time = start_time; - if( report_interval ) - last_report_time = start_time; + if( report_interval ) { + next_report_time = start_time; + timeval_add(&next_report_time, report_interval); + } last_send_time.tv_sec = current_time.tv_sec - 10000; @@ -988,6 +990,7 @@ void main_loop() { long lt; long wait_time; + long wait_time_next_report; HOST_ENTRY *h; while(ev_first) { @@ -1092,6 +1095,15 @@ void main_loop() wait_time = interval; } + /* Make sure we don't wait too long, in case a report is expected */ + if( report_interval && ( loop_flag || count_flag ) ) { + wait_time_next_report = timeval_diff ( ¤t_time, &next_report_time ); + if(wait_time_next_report < wait_time) { + wait_time = wait_time_next_report; + if(wait_time < 0) { wait_time = 0; } + } + } + /* Receive replies */ /* (this is what sleeps during each loop iteration) */ if(wait_for_reply(wait_time)) { @@ -1102,14 +1114,15 @@ void main_loop() /* Print report */ if( report_interval && ( loop_flag || count_flag ) && - ( timeval_diff ( ¤t_time, &last_report_time ) > report_interval ) ) + ( timeval_diff ( ¤t_time, &next_report_time ) >= 0 ) ) { if(netdata_flag) print_netdata(); else print_per_system_splits(); - last_report_time = current_time; + while(timeval_diff ( ¤t_time, &next_report_time ) >= 0 ) + timeval_add(&next_report_time, report_interval); } } }