src/rrd_update.c: Set `rc' correctly when succeeding.
[rrdtool.git] / src / rrd_update.c
index 681dcc4..ffbcebb 100644 (file)
@@ -377,8 +377,6 @@ int rrd_update(
 {
     struct option long_options[] = {
         {"template", required_argument, 0, 't'},
-        {"cache",    optional_argument, 0, 'c'},
-        {"nocache",  no_argument      , 0, 'n'},
         {"daemon",   required_argument, 0, 'd'},
         {0, 0, 0, 0}
     };
@@ -392,7 +390,7 @@ int rrd_update(
     opterr = 0;         /* initialize getopt */
 
     while (1) {
-        opt = getopt_long(argc, argv, "t:cnd:", long_options, &option_index);
+        opt = getopt_long(argc, argv, "t:d:", long_options, &option_index);
 
         if (opt == EOF)
             break;
@@ -432,6 +430,22 @@ int rrd_update(
         goto out;
     }
 
+    if ((tmplt == NULL) && (daemon == NULL))
+    {
+        char *temp;
+
+        temp = getenv (ENV_RRDCACHED_ADDRESS);
+        if (temp != NULL)
+        {
+            daemon = strdup (temp);
+            if (daemon == NULL)
+            {
+                rrd_set_error("strdup failed.");
+                goto out;
+            }
+        }
+    }
+
     if (daemon != NULL)
     {
         int status;
@@ -456,6 +470,10 @@ int rrd_update(
                     ? "Internal error"
                     : rrd_strerror (status));
         }
+        else
+        {
+            rc = 0;
+        }
 
         rrdc_disconnect ();
         goto out;
@@ -565,6 +583,15 @@ int _rrd_update(
                         rra_step_cnt, updvals, tmpl_idx, tmpl_cnt,
                         &pcdp_summary, version, skip_update,
                         &schedule_smooth) == -1) {
+           if (rrd_test_error()) { /* Should have error string always here */
+               char *save_error;
+
+               /* Prepend file name to error message */
+               if ((save_error = strdup(rrd_get_error())) != NULL) {
+                   rrd_set_error("%s: %s", filename, save_error);
+                   free(save_error);
+               }
+           }
             free(arg_copy);
             break;
         }