Skip to content

Commit

Permalink
Merge pull request #185 from laddp/develop
Browse files Browse the repository at this point in the history
Add SIGQUIT summary support similar to ping
  • Loading branch information
schweikert authored Jun 27, 2020
2 parents 25e30da + e064c36 commit 5eff605
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
17 changes: 16 additions & 1 deletion ci/test-07-options-i-m.pl
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -24,6 +24,21 @@
});
}

# 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') {
Expand Down
3 changes: 2 additions & 1 deletion doc/fping.pod
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 29 additions & 0 deletions src/fping.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 5eff605

Please sign in to comment.