Added I18N support for messages printed by rrd_tool.c -- http://oss.oetiker.ch/rrdtoo...
[rrdtool.git] / src / rrd_create.c
index 3d064ff..a8f6a29 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * RRDtool 1.2.23  Copyright by Tobi Oetiker, 1997-2007
+ * RRDtool 1.2.99907080300  Copyright by Tobi Oetiker, 1997-2007
  *****************************************************************************
  * rrd_create.c  creates new rrds
  *****************************************************************************/
@@ -121,14 +121,15 @@ int rrd_create_r(
     /* static header */
     if ((rrd.stat_head = calloc(1, sizeof(stat_head_t))) == NULL) {
         rrd_set_error("allocating rrd.stat_head");
-        rrd_free(&rrd);
+        free(rrd.stat_head);
         return (-1);
     }
 
     /* live header */
     if ((rrd.live_head = calloc(1, sizeof(live_head_t))) == NULL) {
         rrd_set_error("allocating rrd.live_head");
-        rrd_free(&rrd);
+        free(rrd.stat_head);
+        free(rrd.live_head);
         return (-1);
     }
 
@@ -161,7 +162,8 @@ int rrd_create_r(
                                           old_size + sizeof(ds_def_t))) ==
                 NULL) {
                 rrd_set_error("allocating rrd.ds_def");
-                rrd_free(&rrd);
+                free(rrd.stat_head);
+                free(rrd.live_head);
                 return (-1);
             }
             memset(&rrd.ds_def[rrd.stat_head->ds_cnt], 0, sizeof(ds_def_t));
@@ -193,7 +195,8 @@ int rrd_create_r(
                 rrd_set_error("invalid DS format");
             }
             if (rrd_test_error()) {
-                rrd_free(&rrd);
+                free(rrd.stat_head);
+                free(rrd.live_head);
                 return -1;
             }
 
@@ -216,7 +219,8 @@ int rrd_create_r(
             }
 
             if (rrd_test_error()) {
-                rrd_free(&rrd);
+                free(rrd.stat_head);
+                free(rrd.live_head);
                 return -1;
             }
             rrd.stat_head->ds_cnt++;
@@ -229,7 +233,8 @@ int rrd_create_r(
                                            old_size + sizeof(rra_def_t))) ==
                 NULL) {
                 rrd_set_error("allocating rrd.rra_def");
-                rrd_free(&rrd);
+                free(rrd.stat_head);
+                free(rrd.live_head);
                 return (-1);
             }
             memset(&rrd.rra_def[rrd.stat_head->rra_cnt], 0,
@@ -264,6 +269,8 @@ int rrd_create_r(
                         /* initialize some parameters */
                         rrd.rra_def[rrd.stat_head->rra_cnt].
                             par[RRA_seasonal_gamma].u_val = 0.1;
+                        rrd.rra_def[rrd.stat_head->rra_cnt].
+                            par[RRA_seasonal_smoothing_window].u_val = 0.05;
                         /* fall through */
                     case CF_DEVPREDICT:
                         rrd.rra_def[rrd.stat_head->rra_cnt].
@@ -420,6 +427,29 @@ int rrd_create_r(
                             par[RRA_dependent_rra_idx].u_cnt =
                             atoi(token) - 1;
                         break;
+                    case CF_DEVSEASONAL:
+                    case CF_SEASONAL:
+                        /* optional smoothing window */
+                        if (sscanf(token, "smoothing-window=%lf",
+                                   &(rrd.rra_def[rrd.stat_head->rra_cnt].
+                                     par[RRA_seasonal_smoothing_window].
+                                     u_val))) {
+                            strcpy(rrd.stat_head->version, RRD_VERSION);    /* smoothing-window causes Version 4 */
+                            if (rrd.rra_def[rrd.stat_head->rra_cnt].
+                                par[RRA_seasonal_smoothing_window].u_val < 0.0
+                                || rrd.rra_def[rrd.stat_head->rra_cnt].
+                                par[RRA_seasonal_smoothing_window].u_val >
+                                1.0) {
+                                rrd_set_error
+                                    ("Invalid smoothing-window %f: must be between 0 and 1",
+                                     rrd.rra_def[rrd.stat_head->rra_cnt].
+                                     par[RRA_seasonal_smoothing_window].
+                                     u_val);
+                            }
+                        } else {
+                            rrd_set_error("Invalid option %s", token);
+                        }
+                        break;
                     case CF_HWPREDICT:
                     case CF_MHWPREDICT:
                         /* length of the associated CF_SEASONAL and CF_DEVSEASONAL arrays. */
@@ -455,7 +485,8 @@ int rrd_create_r(
                 if (rrd_test_error()) {
                     /* all errors are unrecoverable */
                     free(argvcopy);
-                    rrd_free(&rrd);
+                    free(rrd.stat_head);
+                    free(rrd.live_head);
                     return (-1);
                 }
                 token = strtok_r(NULL, ":", &tokptr);
@@ -482,14 +513,16 @@ int rrd_create_r(
                 if (create_hw_contingent_rras(&rrd, period, hashed_name) ==
                     -1) {
                     rrd_set_error("creating contingent RRA");
-                    rrd_free(&rrd);
+                    free(rrd.stat_head);
+                    free(rrd.live_head);
                     return -1;
                 }
             }
             rrd.stat_head->rra_cnt++;
         } else {
             rrd_set_error("can't parse argument '%s'", argv[i]);
-            rrd_free(&rrd);
+            free(rrd.stat_head);
+            free(rrd.live_head);
             return -1;
         }
     }
@@ -497,13 +530,15 @@ int rrd_create_r(
 
     if (rrd.stat_head->rra_cnt < 1) {
         rrd_set_error("you must define at least one Round Robin Archive");
-        rrd_free(&rrd);
+        free(rrd.stat_head);
+        free(rrd.live_head);
         return (-1);
     }
 
     if (rrd.stat_head->ds_cnt < 1) {
         rrd_set_error("you must define at least one Data Source");
-        rrd_free(&rrd);
+        free(rrd.stat_head);
+        free(rrd.live_head);
         return (-1);
     }
     return rrd_create_fn(filename, &rrd);
@@ -637,10 +672,10 @@ int rrd_create_fn(
     rrd_file_t *rrd_file_dn;
     rrd_t     rrd_dn;
 
-    if ((rrd_file =
-         open(file_name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) == NULL) {
+    if ((rrd_file = open(file_name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
         rrd_set_error("creating '%s': %s", file_name, rrd_strerror(errno));
-        rrd_free(rrd);
+        free(rrd->stat_head);
+        free(rrd->live_head);
         return (-1);
     }
 
@@ -655,7 +690,8 @@ int rrd_create_fn(
 
     if ((rrd->pdp_prep = calloc(1, sizeof(pdp_prep_t))) == NULL) {
         rrd_set_error("allocating pdp_prep");
-        rrd_free(rrd);
+        free(rrd->stat_head);       
+        free(rrd->live_head);       
         close(rrd_file);
         return (-1);
     }
@@ -671,7 +707,8 @@ int rrd_create_fn(
 
     if ((rrd->cdp_prep = calloc(1, sizeof(cdp_prep_t))) == NULL) {
         rrd_set_error("allocating cdp_prep");
-        rrd_free(rrd);
+        free(rrd->stat_head);       
+        free(rrd->live_head);       
         close(rrd_file);
         return (-1);
     }
@@ -718,7 +755,8 @@ int rrd_create_fn(
 
     if ((rrd->rra_ptr = calloc(1, sizeof(rra_ptr_t))) == NULL) {
         rrd_set_error("allocating rra_ptr");
-        rrd_free(rrd);
+        free(rrd->stat_head);       
+        free(rrd->live_head);       
         close(rrd_file);
         return (-1);
     }
@@ -735,7 +773,8 @@ int rrd_create_fn(
     /* write the empty data area */
     if ((unknown = (rrd_value_t *) malloc(512 * sizeof(rrd_value_t))) == NULL) {
         rrd_set_error("allocating unknown");
-        rrd_free(rrd);
+        free(rrd->stat_head);       
+        free(rrd->live_head);       
         close(rrd_file);
         return (-1);
     }
@@ -753,7 +792,8 @@ int rrd_create_fn(
     }
     free(unknown);
     fdatasync(rrd_file);
-    rrd_free(rrd);
+    free(rrd->stat_head);       
+    free(rrd->live_head);       
     if (close(rrd_file) == -1) {
         rrd_set_error("creating rrd: %s", rrd_strerror(errno));
         return -1;
@@ -761,6 +801,7 @@ int rrd_create_fn(
     /* flush all we don't need out of the cache */
     rrd_file_dn = rrd_open(file_name, &rrd_dn, RRD_READONLY);
     rrd_dontneed(rrd_file_dn, &rrd_dn);
+    rrd_free(&rrd_dn);
     rrd_close(rrd_file_dn);
     return (0);
 }