From 9229808c1130b5921776755dac7cac8dc1215191 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Fri, 2 Jun 2006 19:29:15 +0200 Subject: [PATCH] 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. --- src/oping.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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)); -- 2.11.0