]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Make rrd create work via the caching daemon
authorPeter Stamfest <peter@stamfest.at>
Thu, 4 Sep 2014 06:54:46 +0000 (08:54 +0200)
committerPeter Stamfest <peter@stamfest.at>
Thu, 4 Sep 2014 08:24:19 +0000 (10:24 +0200)
src/rrd_client.c
src/rrd_create.c
src/rrd_daemon.c

index 58a3d5b8e42f2de63b765b692b846478433fd823..c53c1ffd946597ec930c51e63fd539185e08595b 100644 (file)
@@ -1248,24 +1248,26 @@ int rrdc_create_r2(const char *filename, /* {{{ */
   }
 
   status = buffer_add_string (filename, &buffer_ptr, &buffer_free);
-  status = buffer_add_string ("-b", &buffer_ptr, &buffer_free);
-  status = buffer_add_ulong (last_up, &buffer_ptr, &buffer_free);
+  if (last_up >= 0) {
+    status = buffer_add_string ("-b", &buffer_ptr, &buffer_free);
+    status = buffer_add_ulong (last_up, &buffer_ptr, &buffer_free);
+  }
   status = buffer_add_string ("-s", &buffer_ptr, &buffer_free);
   status = buffer_add_ulong (pdp_step, &buffer_ptr, &buffer_free);
   if(no_overwrite) {
     status = buffer_add_string ("-O", &buffer_ptr, &buffer_free);
   }
-  
+
   if (sources != NULL) {
     for (const char **p = sources ; *p ; p++) {
-      buffer_add_string ("-r", &buffer_ptr, &buffer_free);
-      buffer_add_string (*p, &buffer_ptr, &buffer_free);
+      status = buffer_add_string ("-r", &buffer_ptr, &buffer_free);
+      status = buffer_add_string (*p, &buffer_ptr, &buffer_free);
     }
   }
   
   if (template != NULL) {
-    buffer_add_string ("-t", &buffer_ptr, &buffer_free);
-    buffer_add_string (template, &buffer_ptr, &buffer_free);
+    status = buffer_add_string ("-t", &buffer_ptr, &buffer_free);
+    status = buffer_add_string (template, &buffer_ptr, &buffer_free);
   }
   
   if (status != 0)
index 5510b173377bf18ceb58b6b009fdb6f7e74a4415..a155e3ad2721d7c17e54d48a09741bbe0928e307 100644 (file)
@@ -779,7 +779,7 @@ int rrd_create_r2(
         rrd_close(tf);
     }
     
-    if (rrd.stat_head->pdp_step == 0) {
+    if (rrd.stat_head->pdp_step <= 0) {
         rrd.stat_head->pdp_step = 300;
     }
 
@@ -876,6 +876,8 @@ int rrd_create_r2(
     rc = rrd_init_data(&rrd);
     if (rc != 0) goto done;
 
+    rc = -1;    // reset rc to default error state
+    
     if (sources != NULL) {
         time_t    sources_latest_last_up = 0;
 
index 81535ef59cbc3eaf44b966f9fcab6bee6f4f4610..4a611e3dc005080531a6dcb3354310d6531649a0 100644 (file)
@@ -1917,8 +1917,8 @@ static int handle_request_create (HANDLER_PROTO) /* {{{ */
   int sources_length = 0;
   char *template = NULL;
   int status;
-  unsigned long step = 300;
-  time_t last_up = time(NULL)-10;
+  unsigned long step = 0;
+  time_t last_up = -1;
   int no_overwrite = opt_no_overwrite;
   int rc = -1;
 
@@ -1988,8 +1988,12 @@ static int handle_request_create (HANDLER_PROTO) /* {{{ */
           rc = send_response(sock, RESP_ERR, "Cannot allocate memory\n");
           goto done;
       }
+      
+      flush_file(tok);
+
       sources[sources_length++] = tok;
-      sources[sources_length + 1] = NULL;
+      sources[sources_length] = NULL;
+
       continue;
     }
     if( ! strncmp(tok,"-t",2) ) {
@@ -1998,6 +2002,8 @@ static int handle_request_create (HANDLER_PROTO) /* {{{ */
           rc = syntax_error(sock,cmd);
           goto done;
       }
+      flush_file(tok);
+
       template = tok;
       continue;
     }
@@ -2010,11 +2016,7 @@ static int handle_request_create (HANDLER_PROTO) /* {{{ */
     rc = syntax_error(sock,cmd);
     goto done;
   }
-  if(step<1) {
-    rc = send_response(sock, RESP_ERR, "The step size cannot be less than 1 second.\n");
-    goto done;
-  }
-  if (last_up < 3600 * 24 * 365 * 10) {
+  if (last_up != -1 && last_up < 3600 * 24 * 365 * 10) {
     rc = send_response(sock, RESP_ERR, "The first entry must be after 1980.\n");
     goto done;
   }