[rrd-developers] [PATCH] client of rrdcached will resolve relative paths to absolute
Tobias Oetiker
tobi at oetiker.ch
Tue Oct 14 21:24:36 CEST 2008
Today kevin brintnall wrote:
> * this preserves principle of least surprise when dealing with files that
> are reachable via many path strings. i.e. when $PWD=/base/dir the
> following files are the same:
>
> /base/dir/x.rrd
> x.rrd
> ../dir/x.rrd
>
> * for performance, absolute paths (starting with '/') are not resolved.
> this reduces the number of stat(2) system calls.
ok
tobi
> ---
> src/rrd_client.c | 10 ++++++++++
> 1 files changed, 10 insertions(+), 0 deletions(-)
>
> diff --git a/src/rrd_client.c b/src/rrd_client.c
> index 76fded0..5583bfe 100644
> --- a/src/rrd_client.c
> +++ b/src/rrd_client.c
> @@ -518,6 +518,7 @@ int rrdc_update (const char *filename, int values_num, /* {{{ */
> rrdc_response_t *res;
> int status;
> int i;
> + char file_path[PATH_MAX];
>
> memset (buffer, 0, sizeof (buffer));
> buffer_ptr = &buffer[0];
> @@ -527,6 +528,10 @@ int rrdc_update (const char *filename, int values_num, /* {{{ */
> if (status != 0)
> return (ENOBUFS);
>
> + /* change to absolute path for rrdcached */
> + if (*filename != '/' && realpath(filename, file_path) != NULL)
> + filename = file_path;
> +
> status = buffer_add_string (filename, &buffer_ptr, &buffer_free);
> if (status != 0)
> return (ENOBUFS);
> @@ -562,6 +567,7 @@ int rrdc_flush (const char *filename) /* {{{ */
> size_t buffer_size;
> rrdc_response_t *res;
> int status;
> + char file_path[PATH_MAX];
>
> if (filename == NULL)
> return (-1);
> @@ -574,6 +580,10 @@ int rrdc_flush (const char *filename) /* {{{ */
> if (status != 0)
> return (ENOBUFS);
>
> + /* change to absolute path for rrdcached */
> + if (*filename != '/' && realpath(filename, file_path) != NULL)
> + filename = file_path;
> +
> status = buffer_add_string (filename, &buffer_ptr, &buffer_free);
> if (status != 0)
> return (ENOBUFS);
>
--
Tobi Oetiker, OETIKER+PARTNER AG, Aarweg 15 CH-4600 Olten, Switzerland
http://it.oetiker.ch tobi at oetiker.ch ++41 62 775 9902 / sb: -9900
More information about the rrd-developers
mailing list