From: Barak A. Pearlmutter Date: Thu, 1 Sep 2011 12:22:05 +0000 (+0100) Subject: non-zero process exit status when too many packets are unreturned X-Git-Tag: liboping-1.7.0~4^2~3 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=6cf6907d4c76235adfb19ca44ea354c8af254e2e;p=liboping.git non-zero process exit status when too many packets are unreturned The number of unreturned packets in excess of 50% is summed over all hosts. If this is nonzero, this count plus 1 is the process exit status. --- diff --git a/src/oping.c b/src/oping.c index 79d7569..5b75dae 100644 --- a/src/oping.c +++ b/src/oping.c @@ -951,9 +951,14 @@ static void update_host_hook (pingobj_iter_t *iter, /* {{{ */ #endif } /* }}} void update_host_hook */ +/* returns the number of significant failures: sum over hosts of + unreturned packets exceeding 50% of the number sent, rounding up. */ static int post_loop_hook (pingobj_t *ping) /* {{{ */ { pingobj_iter_t *iter; + /* failures to report: sum over hosts of number of failed + returns above 50% */ + int failure_count = 0; #if USE_NCURSES endwin (); @@ -973,6 +978,13 @@ static int post_loop_hook (pingobj_t *ping) /* {{{ */ context_get_packet_loss (context), context->latency_total); + { + /* threshold for counting failed returns is 50%, rounding up */ + int threshold = (context->req_sent + 1) / 2; + if (context->req_rcvd < threshold) + failure_count += threshold - context->req_rcvd; + } + if (context->req_rcvd != 0) { double average; @@ -992,7 +1004,7 @@ static int post_loop_hook (pingobj_t *ping) /* {{{ */ context_destroy (context); } - return (0); + return (failure_count); } /* }}} int post_loop_hook */ int main (int argc, char **argv) /* {{{ */ @@ -1281,11 +1293,14 @@ int main (int argc, char **argv) /* {{{ */ opt_count--; } /* while (opt_count != 0) */ - post_loop_hook (ping); + status = post_loop_hook (ping); ping_destroy (ping); - return (0); + if (status) + return (EXIT_FAILURE + status); + else + return (EXIT_SUCCESS); } /* }}} int main */ /* vim: set fdm=marker : */