[rrd-developers] [PATCH] better error strings during rrdcached problems

kevin brintnall kbrint at rufus.net
Mon Sep 29 14:06:18 CEST 2008


This patch provides better error messages to the client when something
goes wrong with the daemon.  When possible, the daemon error message is
passed through to rrd_set_error() on the client.  Prior to this patch,
most error conditions would result in "Internal error", which is not very
helpful.

---
diff --git a/src/rrd_client.c b/src/rrd_client.c
index 7fa9817..44d4d60 100644
--- a/src/rrd_client.c
+++ b/src/rrd_client.c
@@ -212,6 +212,8 @@ static int response_read (rrdc_response_t **ret_response) /* {{{ */
 
   if (ret->status <= 0)
   {
+    if (ret->status < 0)
+      rrd_set_error("rrdcached: %s", ret->message);
     *ret_response = ret;
     return (0);
   }
@@ -266,6 +268,8 @@ static int request (const char *buffer, size_t buffer_size, /* {{{ */
   {
     close_connection ();
     pthread_mutex_unlock (&lock);
+    rrd_set_error("request: socket error (%d) while talking to rrdcached",
+                  status);
     return (-1);
   }
   fflush (sh);
@@ -276,7 +280,11 @@ static int request (const char *buffer, size_t buffer_size, /* {{{ */
   pthread_mutex_unlock (&lock);
 
   if (status != 0)
+  {
+    if (status < 0)
+      rrd_set_error("request: internal error while talking to rrdcached");
     return (status);
+  }
 
   *ret_response = res;
   return (0);
@@ -604,7 +612,7 @@ int rrdc_flush_if_daemon (const char *opt_daemon, const char *filename) /* {{{ *
       rrd_set_error ("rrdc_flush (%s) failed with status %i.",
                      filename, status);
     }
-  } /* if (daemon_addr) */
+  } /* if (rrdc_is_connected(..)) */
 
   return status;
 } /* }}} int rrdc_flush_if_daemon */
diff --git a/src/rrd_update.c b/src/rrd_update.c
index 9d3e854..5e26055 100644
--- a/src/rrd_update.c
+++ b/src/rrd_update.c
@@ -450,13 +450,9 @@ int rrd_update(
         rc = rrdc_update (argv[optind], /* file */
                           argc - optind - 1, /* values_num */
                           (void *) (argv + optind + 1)); /* values */
-        if (rc != 0)
-        {
+        if (rc > 0)
             rrd_set_error("Failed sending the values to rrdcached: %s",
-                    (rc < 0)
-                    ? "Internal error"
-                    : rrd_strerror (rc));
-        }
+                          rrd_strerror (rc));
     }
 
   out:



More information about the rrd-developers mailing list