From: Florian Forster Date: Fri, 2 Jun 2006 17:29:15 +0000 (+0200) Subject: oping: Exit if no hosts could be added. X-Git-Tag: liboping-0.2.2~3 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=9229808c1130b5921776755dac7cac8dc1215191;p=liboping.git oping: Exit if no hosts could be added. If no hosts could be added (e.g. because resolving the hostnames failed) the oping application didn't exit but seemed to hang. Actually it was calling `poll' (or select?) without any file descriptors, and not outputting anything at all. This patch makes oping exit if no hosts could be added to the oping library. --- diff --git a/src/oping.c b/src/oping.c index 18724f4..50c051b 100644 --- a/src/oping.c +++ b/src/oping.c @@ -296,13 +296,14 @@ int main (int argc, char **argv) for (i = optind; i < argc; i++) { - if (ping_host_add (ping, argv[i]) > 0) + if (ping_host_add (ping, argv[i]) < 0) { fprintf (stderr, "ping_host_add (%s) failed\n", argv[i]); continue; } } + i = 0; for (iter = ping_iterator_get (ping); iter != NULL; iter = ping_iterator_next (iter)) @@ -325,6 +326,14 @@ int main (int argc, char **argv) context->host, context->addr, (unsigned int) buffer_size); ping_iterator_set_context (iter, (void *) context); + + i++; + } + + if (i == 0) + { + fprintf (stderr, "No valid hosts left.\n"); + exit (1); } memset (&sigint_action, '\0', sizeof (sigint_action));