]> git.gsnw.org Git - fping.git/commitdiff
Add SIGQUIT summary support similar to ping
authorPatrick Ladd <pladd@redhat.com>
Fri, 12 Jun 2020 22:51:06 +0000 (18:51 -0400)
committerPatrick Ladd <pmladd@gmail.com>
Sun, 21 Jun 2020 20:13:19 +0000 (16:13 -0400)
This reverts commit 3b3877f651af816006ab620f7a189c2c1a3fad8a.

ci/test-07-options-i-m.pl
doc/fping.pod
src/fping.c

index a2517ad6066d4b7c75b14ae6153323ea02cc6b56..6ba20de1e7748e51dd310678f3f54cdbec4784b0 100755 (executable)
@@ -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') {
index 98a9ebbf1c2841ca09f24f1d88a336d883d66fec..ca427d643a6cbc21aa911a7b3e8b41fc059af0f6 100644 (file)
@@ -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<fping> also supports
 sending a specified number of pings to a target, or looping indefinitely (as in
 B<ping> ). Unlike B<ping>, B<fping> 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
 
index a6fd66892f43f57e14ede7d1f9fb0a5703b122e9..f43283369da84bcfe2cc2b8bfefeca9d7c93ea87 100644 (file)
@@ -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(&current_time, NULL);
 
+        if (status_snapshot) {
+            status_snapshot = 0;
+            print_per_system_splits();
+        }
+
         /* Print report */
         if (report_interval && (loop_flag || count_flag) && (timeval_diff(&current_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