From: Florian Forster Date: Wed, 7 Sep 2011 01:08:32 +0000 (-0400) Subject: oping: Make the exit status the number of hosts failed. X-Git-Tag: liboping-1.7.0~4^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=441f2f6f137275321d6bb3d8bfb35f414c580ab6;p=liboping.git oping: Make the exit status the number of hosts failed. As far as I know, EXIT_FAILURE is only portable when used as-is, i.e. without adding anything to it. Especially with "EXIT_FAILURE == -1" we might run into trouble. I think it's more convenient to just use the number of failed hosts rather than 1+ (on Linux). --- diff --git a/src/mans/oping.pod b/src/mans/oping.pod index f0af718..8b8c644 100644 --- a/src/mans/oping.pod +++ b/src/mans/oping.pod @@ -175,6 +175,9 @@ limit will effectively disable the feature (the default). Setting the option to zero means that the exit status will only be zero if I replies for I hosts have been received. +The exit status will indicate the number of hosts with more than I +packets lost, up to a number of 255 failing hosts. + =back =head1 COLORS diff --git a/src/oping.c b/src/oping.c index 37f5fa9..762a3ea 100644 --- a/src/oping.c +++ b/src/oping.c @@ -972,8 +972,9 @@ static void update_host_hook (pingobj_iter_t *iter, /* {{{ */ #endif } /* }}} void update_host_hook */ -/* Returns the number of hosts which failed to return more than the - fraction opt_exit_status_threshold of pings */ +/* Prints statistics for each host, cleans up the contexts and returns the + * number of hosts which failed to return more than the fraction + * opt_exit_status_threshold of pings. */ static int post_loop_hook (pingobj_t *ping) /* {{{ */ { pingobj_iter_t *iter; @@ -1312,14 +1313,19 @@ int main (int argc, char **argv) /* {{{ */ opt_count--; } /* while (opt_count != 0) */ + /* Returns the number of failed hosts according to -Z. */ status = post_loop_hook (ping); ping_destroy (ping); - if (status) - return (EXIT_FAILURE + status); + if (status == 0) + exit (EXIT_SUCCESS); else - return (EXIT_SUCCESS); + { + if (status > 255) + status = 255; + exit (status); + } } /* }}} int main */ /* vim: set fdm=marker : */