src/rrd_daemon.c: Removed semi-automatic usage of the daemon.
authorFlorian Forster <octo@leeloo.home.verplant.org>
Tue, 24 Jun 2008 19:00:33 +0000 (21:00 +0200)
committerFlorian Forster <octo@leeloo.home.verplant.org>
Tue, 24 Jun 2008 19:00:33 +0000 (21:00 +0200)
With remote servers and relative paths failing silently is just too
dangerous. We shouldn't allow the user to shoot herself in the foot.

src/rrd_update.c

index d978822..681dcc4 100644 (file)
@@ -318,42 +318,6 @@ static inline void initialize_time(
     }
 }
 
-static int send_values_to_daemon (const char *addr, const char *file,
-        int values_num, const char * const *values, int silent)
-{
-    int status;
-
-    status = rrdc_connect ((addr != NULL) ? addr : RRDD_SOCK_PATH);
-    if (status != 0)
-    {
-        if (!silent)
-        {
-            rrd_set_error("Unable to connect to daemon: %s",
-                    (status < 0)
-                    ? "Internal error"
-                    : rrd_strerror (status));
-        }
-        return (status);
-    }
-
-    status = rrdc_update (file, values_num, values);
-    if (status != 0)
-    {
-        if (!silent)
-        {
-            rrd_set_error("Failed sending the values to the daemon: %s",
-                    (status < 0)
-                    ? "Internal error"
-                    : rrd_strerror (status));
-        }
-        rrdc_disconnect ();
-        return (status);
-    }
-
-    rrdc_disconnect ();
-    return (0);
-} /* int send_values_to_daemon */
-
 #define IFDNAN(X,Y) (isnan(X) ? (Y) : (X));
 
 rrd_info_t *rrd_update_v(
@@ -422,9 +386,7 @@ int rrd_update(
     int       opt;
     char     *tmplt = NULL;
     int       rc = -1;
-    /* force_cache: 0 = default; -1 = force no cache; 1 = force cache */
-    int       force_cache = 0;
-    char     *daemon_address = NULL;
+    char     *daemon = NULL;
 
     optind = 0;
     opterr = 0;         /* initialize getopt */
@@ -440,33 +402,11 @@ int rrd_update(
             tmplt = strdup(optarg);
             break;
 
-        case 'c':
-            if (optarg != NULL)
-            {
-                if (strcmp ("no", optarg) == 0)
-                    force_cache = -1;
-                else if (strcmp ("yes", optarg) == 0)
-                    force_cache = 1;
-                else
-                {
-                    rrd_set_error ("option 'cache' must be "
-                            "either 'yes' or 'no'.");
-                    goto out;
-                }
-            }
-            else
-                force_cache = 1;
-            break;
-
-        case 'n':
-            force_cache = -1;
-            break;
-
         case 'd':
-            if (daemon_address != NULL)
-                free (daemon_address);
-            daemon_address = strdup (optarg);
-            if (daemon_address == NULL)
+            if (daemon != NULL)
+                free (daemon);
+            daemon = strdup (optarg);
+            if (daemon == NULL)
             {
                 rrd_set_error("strdup failed.");
                 goto out;
@@ -485,25 +425,41 @@ int rrd_update(
         goto out;
     }
 
-    if ((tmplt != NULL) && (force_cache > 0))
+    if ((tmplt != NULL) && (daemon != NULL))
     {
         rrd_set_error("The caching daemon cannot be used together with "
                 "templates yet.");
         goto out;
     }
 
-    if ((tmplt == NULL) && (force_cache >= 0))
+    if (daemon != NULL)
     {
         int status;
 
-        status = send_values_to_daemon (daemon_address,
-                /* file = */ argv[optind],
-                /* values_num = */ argc - optind - 1,
-                /* values = */ (void *) (argv + optind + 1),
-                /* silent = */ (force_cache > 0) ? 0 : 1);
-        if ((status == 0) || (force_cache > 0))
+        status = rrdc_connect (daemon);
+        if (status != 0)
+        {
+            rrd_set_error("Unable to connect to daemon: %s",
+                    (status < 0)
+                    ? "Internal error"
+                    : rrd_strerror (status));
             goto out;
-    } /* if ((tmplt != NULL) && (force_cache >= 0)) */
+        }
+
+        status = rrdc_update (/* file = */ argv[optind],
+                /* values_num = */ argc - optind - 1,
+                /* values = */ (void *) (argv + optind + 1));
+        if (status != 0)
+        {
+            rrd_set_error("Failed sending the values to the daemon: %s",
+                    (status < 0)
+                    ? "Internal error"
+                    : rrd_strerror (status));
+        }
+
+        rrdc_disconnect ();
+        goto out;
+    } /* if (daemon != NULL) */
 
     rc = rrd_update_r(argv[optind], tmplt,
                       argc - optind - 1, (const char **) (argv + optind + 1));
@@ -513,10 +469,10 @@ int rrd_update(
         free(tmplt);
         tmplt = NULL;
     }
-    if (daemon_address != NULL)
+    if (daemon != NULL)
     {
-        free (daemon_address);
-        daemon_address = NULL;
+        free (daemon);
+        daemon = NULL;
     }
     return rc;
 }