From: Martin Sperl Date: Mon, 5 May 2014 16:10:31 +0000 (+0000) Subject: added option to strip path away when using rrdcached X-Git-Tag: v1.5.0-rc1~109^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff5e3c2c3b4f6a18794eff9d290c4bc164d4d31f;p=thirdparty%2Frrdtool-1.x.git added option to strip path away when using rrdcached --- diff --git a/doc/rrdupdate.pod b/doc/rrdupdate.pod index c5fdc345..7be2da08 100644 --- a/doc/rrdupdate.pod +++ b/doc/rrdupdate.pod @@ -120,6 +120,13 @@ If this environment variable is set it will have the same effect as specifying the C<--daemon> option on the command line. If both are present, the command line argument takes precedence. +=item B + +If this environment variable is set it will strip the leading string from the +filename prior to sending the filename to rrdcached. +This is mostly intended to allow rrdcached to work with xymon and cacti tools +without having to modify those tools. + =back =head1 EXAMPLES diff --git a/src/rrd_client.c b/src/rrd_client.c index e2871e0e..6c7b46ce 100644 --- a/src/rrd_client.c +++ b/src/rrd_client.c @@ -84,6 +84,8 @@ static size_t inbuf_used = 0; static const char *get_path (const char *path, char *resolved_path) /* {{{ */ { const char *ret = path; + const char *strip = getenv(ENV_RRDCACHED_STRIPPATH); + size_t len; int is_unix = 0; if ((path == NULL) || (resolved_path == NULL) || (sd_path == NULL)) @@ -104,7 +106,17 @@ static const char *get_path (const char *path, char *resolved_path) /* {{{ */ { if (*path == '/') /* not absolute path */ { - rrd_set_error ("absolute path names not allowed when talking " + /* if we are stripping, then check and remove the head */ + if (strip) { + len = strlen(strip); + if (strncmp(path,strip,len)==0) { + path += len; + while (*path == '/') + path++; + return path; + } + } else + rrd_set_error ("absolute path names not allowed when talking " "to a remote daemon"); return NULL; } diff --git a/src/rrd_client.h b/src/rrd_client.h index af66d775..873f5b90 100644 --- a/src/rrd_client.h +++ b/src/rrd_client.h @@ -40,7 +40,7 @@ #define RRDCACHED_DEFAULT_PORT "42217" #define ENV_RRDCACHED_ADDRESS "RRDCACHED_ADDRESS" - +#define ENV_RRDCACHED_STRIPPATH "RRDCACHED_STRIPPATH" int rrdc_connect (const char *addr); int rrdc_is_connected(const char *daemon_addr);