[rrd-developers] rrdcached CREATE: the daemon should mkdir -p

Marek.Schimara at ext.bull.net Marek.Schimara at ext.bull.net
Thu Apr 26 17:31:30 CEST 2012


Hello,

I compiled the current trunk (r2287) and noticed that rrdcached can't 
create a RRD if the whole path to it doesn't exist; for example:

telnet localhost 42217
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
CREATE a/b/c.rrd -b 1335447997 DS:one:COUNTER:600:U:U RRA:AVERAGE:0.5:1:24
-1 RRD Error: creating '/home/tests/rrd/data/a/b/c.rrd': No such file or 
directory
CREATE c.rrd -b 1335447997 DS:one:COUNTER:600:U:U RRA:AVERAGE:0.5:1:24
0 RRD created OK
QUIT

where /home/tests/rrd/data is the daemons basedir. Could the following 
patch be considered?

--- rrd_daemon.c        (revision 2287)
+++ rrd_daemon.c        (working copy)
@@ -1824,6 +1824,8 @@
 static int handle_request_create (HANDLER_PROTO) /* {{{ */
 {
   char *file, file_tmp[PATH_MAX];
+  char *file_copy, *dir;
+  struct stat st;
   char *tok;
   int ac = 0;
   char *av[128];
@@ -1839,6 +1841,17 @@
     return syntax_error(sock,cmd);
   /* get full pathname */
   get_abs_path(&file, file_tmp);
+  /* dirname may modify its argument */
+  file_copy = strdup(file);
+  if (file_copy == NULL) {
+    return send_response(sock, RESP_ERR, "Cannot create: empty 
argument.\n");
+  }
+  dir = dirname(file_copy);
+  if (stat(dir, &st) != 0) {
+      if (rrd_mkdir_p(dir, 0755) != 0) {
+        return send_response(sock, RESP_ERR, "Cannot create: %s\n", dir);
+      }
+  }
   if (!check_file_access(file, sock)) {
     return send_response(sock, RESP_ERR, "Cannot read: %s\n", file);
   }

This would avoid having to connect to the remote machine which is running 
rrdcached only to create directory, and would allow to start rrdcached 
with an empty file tree and construct it as needed directly via the 
daemons' CREATE commands.
I guess the mode argument to rrd_mkdir_p() could be something better than 
a magic number :-) but I'm not sure what..


thanks & regards
Marek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.oetiker.ch/pipermail/rrd-developers/attachments/20120426/62932663/attachment.htm 


More information about the rrd-developers mailing list