From e064c36df874657983741eb65c099052f7a0b024 Mon Sep 17 00:00:00 2001 From: Patrick Ladd Date: Fri, 12 Jun 2020 18:51:06 -0400 Subject: [PATCH] Add SIGQUIT summary support similar to ping This reverts commit 3b3877f651af816006ab620f7a189c2c1a3fad8a. --- ci/test-07-options-i-m.pl | 17 ++++++++++++++++- doc/fping.pod | 3 ++- src/fping.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/ci/test-07-options-i-m.pl b/ci/test-07-options-i-m.pl index a2517ad..6ba20de 100755 --- a/ci/test-07-options-i-m.pl +++ b/ci/test-07-options-i-m.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -use Test::Command tests => 7; +use Test::Command tests => 9; use Test::More; # -i n interval between sending ping packets (in millisec) (default 25) @@ -24,6 +24,21 @@ $cmd->stdout_like(qr{127\.0\.0\.1 : \[0\], 84 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0 }); } +# fping -l with SIGQUIT +{ +my $cmd = Test::Command->new(cmd => '(sleep 2; pkill -QUIT fping; sleep 2; pkill fping)& fping -p 900 -l 127.0.0.1'); +$cmd->stdout_like(qr{127\.0\.0\.1 : \[0\], 84 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) +127\.0\.0\.1 : \[1\], 84 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) +127\.0\.0\.1 : \[2\], 84 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) +127\.0\.0\.1 : \[3\], 84 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) +127\.0\.0\.1 : \[4\], 84 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) +}); +$cmd->stderr_like(qr{\[\d+:\d+:\d+\] +127\.0\.0\.1 : xmt/rcv/%loss = \d+/\d+/\d+%, min/avg/max = \d+\.\d+/\d+\.\d+/\d+\.\d+ +}); +} + + # fping -M SKIP: { if($^O eq 'darwin') { diff --git a/doc/fping.pod b/doc/fping.pod index 98a9ebb..ca427d6 100644 --- a/doc/fping.pod +++ b/doc/fping.pod @@ -19,7 +19,8 @@ of targets to check; if a target does not respond within a certain time limit and/or retry limit it is designated as unreachable. B also supports sending a specified number of pings to a target, or looping indefinitely (as in B ). Unlike B, B is meant to be used in scripts, so its -output is designed to be easy to parse. +output is designed to be easy to parse. Current statistics can be obtained without +termination of process with signal SIGQUIT (^\ from the keyboard on most systems). =head1 OPTIONS diff --git a/src/fping.c b/src/fping.c index a6fd668..f432833 100644 --- a/src/fping.c +++ b/src/fping.c @@ -252,6 +252,8 @@ int socket6 = -1; int hints_ai_family = AF_UNSPEC; #endif +volatile sig_atomic_t status_snapshot = 0; + unsigned int debugging = 0; /* times get *100 because all times are calculated in 10 usec units, not ms */ @@ -329,6 +331,7 @@ void print_per_system_splits(void); void print_netdata(void); void print_global_stats(void); void main_loop(); +void sigstatus(); void finish(); char* sprint_tm(int t); void ev_enqueue(HOST_ENTRY* h); @@ -1027,6 +1030,7 @@ int main(int argc, char** argv) #endif signal(SIGINT, finish); + signal(SIGQUIT, sigstatus); gettimeofday(&start_time, NULL); current_time = start_time; @@ -1302,6 +1306,11 @@ void main_loop() gettimeofday(¤t_time, NULL); + if (status_snapshot) { + status_snapshot = 0; + print_per_system_splits(); + } + /* Print report */ if (report_interval && (loop_flag || count_flag) && (timeval_diff(¤t_time, &next_report_time) >= 0)) { if (netdata_flag) @@ -1315,6 +1324,26 @@ void main_loop() } } +/************************************************************ + + Function: sigstatus + +************************************************************* + + Inputs: void (none) + + Description: + + SIGQUIT signal handler - set flag and return + +************************************************************/ + +void sigstatus() +{ + status_snapshot = 1; +} + + /************************************************************ Function: finish