From: Erik Auerswald Date: Wed, 7 Feb 2024 18:36:48 +0000 (+0100) Subject: Decouple -a/-u effects from -c X-Git-Url: https://git.gsnw.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1443614dad51b392741d584bb90fb8e6e97bb26a;p=fping.git Decouple -a/-u effects from -c As described in issue #295, the option combinations "-c N -u" and "-c N -a" inadvertently have the same effect as "-c N -q". Prevent this by first acting on -c, which includes disabling either -a or -u, if -c is given, before acting on -a/-u. --- diff --git a/ci/test-05-options-c-e.pl b/ci/test-05-options-c-e.pl index 7bbe68c..a5b34d2 100755 --- a/ci/test-05-options-c-e.pl +++ b/ci/test-05-options-c-e.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -use Test::Command tests => 18; +use Test::Command tests => 33; # -c n count of pings to send to each target (default 1) # -C n same as -c, report results in verbose format @@ -22,6 +22,46 @@ $cmd->stderr_like(qr{localhost : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\ }); } +# fping -c n -q +{ +my $cmd = Test::Command->new(cmd => "fping -q -c 2 -p 100 localhost 127.0.0.1"); +$cmd->exit_is_num(0); +$cmd->stdout_is_eq(""); +$cmd->stderr_like(qr{localhost : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+ +127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+ +}); +} + +# fping -c n -a (-a is ignored) +{ +my $cmd = Test::Command->new(cmd => "fping -a -c 2 -p 100 localhost 127.0.0.1"); +$cmd->exit_is_num(0); +$cmd->stdout_like(qr{localhost : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) +127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) +localhost : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) +127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) +}); + +$cmd->stderr_like(qr{localhost : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+ +127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+ +}); +} + +# fping -c n -u (-u is ignored) +{ +my $cmd = Test::Command->new(cmd => "fping -u -c 2 -p 100 localhost 127.0.0.1"); +$cmd->exit_is_num(0); +$cmd->stdout_like(qr{localhost : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) +127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) +localhost : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) +127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) +}); + +$cmd->stderr_like(qr{localhost : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+ +127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+ +}); +} + # fping -C n { my $cmd = Test::Command->new(cmd => "fping -4 -C 2 -p 100 localhost 127.0.0.1"); @@ -46,6 +86,36 @@ $cmd->stderr_like(qr{localhost :( \d\.\d+){5} }); } +# fping -C n -a (-a is ignored) +{ +my $cmd = Test::Command->new(cmd => "fping -a -C 2 -p 100 localhost 127.0.0.1"); +$cmd->exit_is_num(0); +$cmd->stdout_like(qr{localhost : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) +127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) +localhost : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) +127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) +}); + +$cmd->stderr_like(qr{localhost : \d\.\d+ \d\.\d+ +127\.0\.0\.1 : \d\.\d+ \d\.\d+ +}); +} + +# fping -C n -u (-u is ignored) +{ +my $cmd = Test::Command->new(cmd => "fping -u -C 2 -p 100 localhost 127.0.0.1"); +$cmd->exit_is_num(0); +$cmd->stdout_like(qr{localhost : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) +127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) +localhost : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) +127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) +}); + +$cmd->stderr_like(qr{localhost : \d\.\d+ \d\.\d+ +127\.0\.0\.1 : \d\.\d+ \d\.\d+ +}); +} + # fping -C n -i -q { my $cmd = Test::Command->new(cmd => "fping --quiet --interval=1 --vcount=20 --period=50 127.0.0.1 127.0.0.2"); diff --git a/src/fping.c b/src/fping.c index e2ee8b0..820eaef 100644 --- a/src/fping.c +++ b/src/fping.c @@ -919,9 +919,6 @@ int main(int argc, char **argv) exit(1); } - if (alive_flag || unreachable_flag || min_reachable) - verbose_flag = 0; - if (count_flag) { if (verbose_flag) per_recv_flag = 1; @@ -936,6 +933,9 @@ int main(int argc, char **argv) alive_flag = unreachable_flag = verbose_flag = 0; } + if (alive_flag || unreachable_flag || min_reachable) + verbose_flag = 0; + trials = (count > retry + 1) ? count : retry + 1; /* auto-tune default timeout for count/loop modes