Big bunch of improvements for the caching daemon.
[rrdtool.git] / src / rrd_dump.c
index 093e7d2..a32f4fb 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * RRDtool 1.3.0  Copyright by Tobi Oetiker, 1997-2008
+ * RRDtool 1.3.2  Copyright by Tobi Oetiker, 1997-2008
  *****************************************************************************
  * rrd_dump  Display a RRD
  *****************************************************************************
@@ -442,7 +442,7 @@ int rrd_dump(
 {
     int       rc;
     int       opt_noheader = 0;
-    char     *rrdcached = NULL;
+    char     *opt_daemon = NULL;
 
     /* init rrd clean */
 
@@ -465,10 +465,10 @@ int rrd_dump(
 
         switch (opt) {
         case 'd':
-            if (rrdcached != NULL)
-                    free (rrdcached);
-            rrdcached = strdup (optarg);
-            if (rrdcached == NULL)
+            if (opt_daemon != NULL)
+                    free (opt_daemon);
+            opt_daemon = strdup (optarg);
+            if (opt_daemon == NULL)
             {
                 rrd_set_error ("strdup failed.");
                 return (-1);
@@ -493,43 +493,9 @@ int rrd_dump(
         return (-1);
     }
 
-    if (rrdcached == NULL)
-    {
-        char *temp;
-
-        temp = getenv (ENV_RRDCACHED_ADDRESS);
-        if (temp != NULL)
-        {
-            rrdcached = strdup (temp);
-            if (rrdcached == NULL)
-            {
-                rrd_set_error("strdup failed.");
-                return (-1);
-            }
-        }
-    }
-
-    if (rrdcached != NULL)
-    {
-        int status;
-
-        status = rrdc_connect (rrdcached);
-        if (status != 0)
-        {
-            rrd_set_error ("rrdc_connect failed with status %i.", status);
-            return (-1);
-        }
-
-        status = rrdc_flush (argv[optind]);
-        if (status != 0)
-        {
-            rrd_set_error ("rrdc_flush (%s) failed with status %i.",
-                    argv[optind], status);
-            return (-1);
-        }
-
-        rrdc_disconnect ();
-    } /* if (rrdcached) */
+    rc = rrdc_flush_if_daemon(opt_daemon, argv[optind]);
+    if (opt_daemon) free(opt_daemon);
+    if (rc) return (rc);
 
     if ((argc - optind) == 2) {
         rc = rrd_dump_opt_r(argv[optind], argv[optind + 1], opt_noheader);