From af9b3bfbfec9b2181296e8050f15ad71cec334a4 Mon Sep 17 00:00:00 2001 From: deepak0004 Date: Sat, 27 Oct 2018 22:58:01 +0530 Subject: [PATCH] Adding separate exit codes for success or failure, and printing the number of reachable hosts --- ci/test-10-option-u-x.pl | 4 ++-- src/fping.c | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ci/test-10-option-u-x.pl b/ci/test-10-option-u-x.pl index 49b9120..35a5bc4 100755 --- a/ci/test-10-option-u-x.pl +++ b/ci/test-10-option-u-x.pl @@ -27,14 +27,14 @@ $cmd->stderr_is_eq(""); { my $cmd = Test::Command->new(cmd => "fping -x 1 8.8.0.0 127.0.0.1"); $cmd->exit_is_num(0); -$cmd->stdout_is_eq(">=1 hosts are reachable\n"); +$cmd->stdout_is_eq("Number of reachable hosts: 1\n"); $cmd->stderr_is_eq(""); } # fping -x { my $cmd = Test::Command->new(cmd => "fping -x 2 8.8.0.0 127.0.0.1"); -$cmd->exit_is_num(0); +$cmd->exit_is_num(1); $cmd->stdout_is_eq("<2 hosts are reachable\n"); $cmd->stderr_is_eq(""); } diff --git a/src/fping.c b/src/fping.c index 8964215..c157255 100644 --- a/src/fping.c +++ b/src/fping.c @@ -1334,11 +1334,12 @@ void finish() if (reachable_flag) { if ((num_hosts-num_unreachable >= reachable)) { - printf(">=%d hosts are reachable\n", reachable); + printf("Number of reachable hosts: %d\n", num_hosts-num_unreachable); + exit(0); } else { printf("<%d hosts are reachable\n", reachable); + exit(1); } - exit(0); } if (num_noaddress) -- 2.43.0