only release cairo stuff if we ever initialized it.
[rrdtool.git] / src / rrd_update.c
index abe9704..174953d 100644 (file)
@@ -14,6 +14,8 @@
 #include <io.h>
 #endif
 
+#include <locale.h>
+
 #include "rrd_hw.h"
 #include "rrd_rpncalc.h"
 
@@ -135,16 +137,16 @@ info_t   *rrd_update_v(
     char     *tmplt = NULL;
     info_t   *result = NULL;
     infoval   rc;
+    struct option long_options[] = {
+        {"template", required_argument, 0, 't'},
+        {0, 0, 0, 0}
+    };
 
     rc.u_int = -1;
     optind = 0;
     opterr = 0;         /* initialize getopt */
 
     while (1) {
-        static struct option long_options[] = {
-            {"template", required_argument, 0, 't'},
-            {0, 0, 0, 0}
-        };
         int       option_index = 0;
         int       opt;
 
@@ -500,8 +502,11 @@ int _rrd_update(
             current_time_usec = tmp_time.tv_usec;
         } else {
             double    tmp;
+            char     *old_locale;
 
+            old_locale = setlocale(LC_NUMERIC, "C");
             tmp = strtod(updvals[0], 0);
+            setlocale(LC_NUMERIC, old_locale);
             current_time = floor(tmp);
             current_time_usec =
                 (long) ((tmp - (double) current_time) * 1000000.0);
@@ -593,6 +598,7 @@ int _rrd_update(
                 (dst_idx != DST_CDEF) &&
                 rrd.ds_def[i].par[DS_mrhb_cnt].u_cnt >= interval) {
                 double    rate = DNAN;
+                char     *old_locale;
 
                 /* the data source type defines how to process the data */
                 /* pdp_new contains rate * time ... eg the bytes
@@ -601,23 +607,21 @@ int _rrd_update(
                 switch (dst_idx) {
                 case DST_COUNTER:
                 case DST_DERIVE:
-                    if (rrd.pdp_prep[i].last_ds[0] != 'U') {
-                        for (ii = 0; updvals[i + 1][ii] != '\0'; ii++) {
-                            if ((updvals[i + 1][ii] < '0'
-                                 || updvals[i + 1][ii] > '9') && (ii != 0
-                                                                  && updvals[i
-                                                                             +
-                                                                             1]
-                                                                  [ii] !=
-                                                                  '-')) {
-                                rrd_set_error("not a simple integer: '%s'",
-                                              updvals[i + 1]);
-                                break;
-                            }
-                        }
-                        if (rrd_test_error()) {
+                    for (ii = 0; updvals[i + 1][ii] != '\0'; ii++) {
+                        if ((updvals[i + 1][ii] < '0'
+                             || updvals[i + 1][ii] > '9') && (ii != 0
+                                                              && updvals[i
+                                                                         + 1]
+                                                              [ii] != '-')) {
+                            rrd_set_error("not a simple integer: '%s'",
+                                          updvals[i + 1]);
                             break;
                         }
+                    }
+                    if (rrd_test_error()) {
+                        break;
+                    }
+                    if (rrd.pdp_prep[i].last_ds[0] != 'U') {
                         pdp_new[i] =
                             rrd_diff(updvals[i + 1], rrd.pdp_prep[i].last_ds);
                         if (dst_idx == DST_COUNTER) {
@@ -636,8 +640,10 @@ int _rrd_update(
                     }
                     break;
                 case DST_ABSOLUTE:
+                    old_locale = setlocale(LC_NUMERIC, "C");
                     errno = 0;
                     pdp_new[i] = strtod(updvals[i + 1], &endptr);
+                    setlocale(LC_NUMERIC, old_locale);
                     if (errno > 0) {
                         rrd_set_error("converting '%s' to float: %s",
                                       updvals[i + 1], rrd_strerror(errno));
@@ -653,7 +659,9 @@ int _rrd_update(
                     break;
                 case DST_GAUGE:
                     errno = 0;
+                    old_locale = setlocale(LC_NUMERIC, "C");
                     pdp_new[i] = strtod(updvals[i + 1], &endptr) * interval;
+                    setlocale(LC_NUMERIC, old_locale);
                     if (errno > 0) {
                         rrd_set_error("converting '%s' to float: %s",
                                       updvals[i + 1], rrd_strerror(errno));
@@ -1198,6 +1206,7 @@ int _rrd_update(
                                     u_val = seasonal_coef[ii];
                                 break;
                             case CF_HWPREDICT:
+                            case CF_MHWPREDICT:
                                 /* need to update the null_count and last_null_count.
                                  * even do this for non-DNAN pdp_temp because the
                                  * algorithm is not learning from batch updates. */
@@ -1442,19 +1451,7 @@ int _rrd_update(
         goto err_free_pdp_new;
     }
 #endif
-#ifdef HAVE_POSIX_FADVISExxx
 
-    /* with update we have write ops, so they will probably not be done by now, this means
-       the buffers will not get freed. But calling this for the whole file - header
-       will let the data off the hook as soon as it is written when if it is from a previous
-       update cycle. Calling fdsync to force things is much too hard here. */
-
-    if (0 != posix_fadvise(rrd_file->fd, rra_begin, 0, POSIX_FADV_DONTNEED)) {
-        rrd_set_error("setting POSIX_FADV_DONTNEED on '%s': %s", filename,
-                      rrd_strerror(errno));
-        goto err_free_pdp_new;
-    }
-#endif
     /* rrd_flush(rrd_file); */
 
     /* calling the smoothing code here guarantees at most
@@ -1478,17 +1475,9 @@ int _rrd_update(
             rra_start += rrd.rra_def[i].row_cnt
                 * rrd.stat_head->ds_cnt * sizeof(rrd_value_t);
         }
-#ifdef HAVE_POSIX_FADVISExxx
-        /* same procedure as above ... */
-        if (0 !=
-            posix_fadvise(rrd_file->fd, rra_begin, 0, POSIX_FADV_DONTNEED)) {
-            rrd_set_error("setting POSIX_FADV_DONTNEED on '%s': %s", filename,
-                          rrd_strerror(errno));
-            goto err_free_pdp_new;
-        }
-#endif
     }
 
+/*    rrd_dontneed(rrd_file,&rrd); */
     rrd_free(&rrd);
     rrd_close(rrd_file);