From c207f0ca4e3eca8d8bbd897884ae3ad8f8e9859d Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sun, 11 Nov 2012 10:57:55 +0100 Subject: [PATCH] ping plugin: Don't abort the "ping_thread" when ping_send() fails. This may happen when the network is down. If the thread fails, the read callback will indicate an error and the exponential back-off will start. This is not optimal for this scenario, since you usually want to have ping stats from right when the network is back up. Fixes Github issue #171. --- src/ping.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/ping.c b/src/ping.c index 51a7e777..ab1459e3 100644 --- a/src/ping.c +++ b/src/ping.c @@ -23,6 +23,7 @@ #include "common.h" #include "plugin.h" #include "configfile.h" +#include "utils_complain.h" #include #include @@ -245,6 +246,8 @@ static void *ping_thread (void *arg) /* {{{ */ hostlist_t *hl; int count; + c_complain_t complaint = C_COMPLAIN_INIT_STATIC; + pthread_mutex_lock (&ping_lock); pingobj = ping_construct (); @@ -305,6 +308,7 @@ static void *ping_thread (void *arg) /* {{{ */ while (ping_thread_loop > 0) { int status; + _Bool send_successful = 0; if (gettimeofday (&tv_begin, NULL) < 0) { @@ -320,10 +324,13 @@ static void *ping_thread (void *arg) /* {{{ */ status = ping_send (pingobj); if (status < 0) { - ERROR ("ping plugin: ping_send failed: %s", ping_get_error (pingobj)); - pthread_mutex_lock (&ping_lock); - ping_thread_error = 1; - break; + c_complain (LOG_ERR, &complaint, "ping plugin: ping_send failed: %s", + ping_get_error (pingobj)); + } + else + { + c_release (LOG_NOTICE, &complaint, "ping plugin: ping_send succeeded."); + send_successful = 1; } pthread_mutex_lock (&ping_lock); @@ -331,7 +338,8 @@ static void *ping_thread (void *arg) /* {{{ */ if (ping_thread_loop <= 0) break; - (void) ping_dispatch_all (pingobj); + if (send_successful) + (void) ping_dispatch_all (pingobj); if (gettimeofday (&tv_end, NULL) < 0) { -- 2.30.2