[rrd-developers] rrdcached CREATE: the daemon should mkdir -p
Steve Shipway
s.shipway at auckland.ac.nz
Thu Apr 26 21:49:42 CEST 2012
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
s.shipway at auckland.ac.nz<mailto:s.shipway at auckland.ac.nz>
Ph: +64 9 373 7599 ext 86487
________________________________
From: rrd-developers-bounces+steve=steveshipway.org at lists.oetiker.ch [rrd-developers-bounces+steve=steveshipway.org at lists.oetiker.ch] on behalf of Marek.Schimara at ext.bull.net [Marek.Schimara at ext.bull.net]
Sent: Friday, 27 April 2012 3:31 a.m.
To: rrd-developers at lists.oetiker.ch
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.oetiker.ch/pipermail/rrd-developers/attachments/20120426/a632139f/attachment-0001.htm
More information about the rrd-developers
mailing list