I like this as an option, but I think it should be an option to rrdcached (eg: 
-p : allow rrdcached to create paths ) that supplements the 'allow create of 
rrd files' option?  I dont think everyone will necessarily want rrdcached to be 
able to create a directory structure (eg: I wouldnt, as this would indicate 
something going wrong elsewhere)

Steve

Steve Shipway
University of Auckland ITS
UNIX Systems Design Lead
[email protected]<mailto:[email protected]>
Ph: +64 9 373 7599 ext 86487

________________________________
From: [email protected] 
[[email protected]] on behalf of 
[email protected] [[email protected]]
Sent: Friday, 27 April 2012 3:31 a.m.
To: [email protected]
Subject: [rrd-developers] rrdcached CREATE: the daemon should mkdir -p

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
_______________________________________________
rrd-developers mailing list
[email protected]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-developers

Reply via email to