* into existing solutions (as requested by Tobi). Else, absolute path names
* are not allowed, since path name translation is done by the server.
*
+ * The caller must call free() on the returned value.
+ *
* One must hold `lock' when calling this function. */
-static const char *get_path (const char *path, char *resolved_path) /* {{{ */
+static char *get_path (const char *path) /* {{{ */
{
- const char *ret = path;
+ char *ret = NULL;
const char *strip = getenv(ENV_RRDCACHED_STRIPPATH);
size_t len;
int is_unix = 0;
- if ((path == NULL) || (resolved_path == NULL) || (sd_path == NULL))
+ if ((path == NULL) || (sd_path == NULL))
return (NULL);
if ((*sd_path == '/')
if (is_unix)
{
if (path == NULL || strlen(path) == 0) return NULL;
- ret = realpath(path, resolved_path);
+ ret = realpath(path, NULL);
if (ret == NULL) {
/* this may happen, because the file DOES NOT YET EXIST (as would be
* the case for rrdcreate) - retry by stripping the last path element,
* resolving the directory and re-concatenate them.... */
- char buffer[PATH_MAX];
+ char *dir_path;
char *lastslash = strrchr(path, '/');
-
char *dir = (lastslash == NULL || lastslash == path) ? strdup(".")
#ifdef HAVE_STRNDUP
: strndup(path, lastslash - path);
}
#endif
if (dir != NULL) {
- ret = realpath(dir, buffer);
+ dir_path = realpath(dir, NULL);
free(dir);
- if (ret == NULL) {
+ if (dir_path == NULL) {
rrd_set_error("realpath(%s): %s", path, rrd_strerror(errno));
+ return NULL;
+ }
+ ret = malloc(strlen(dir_path)
+ + (lastslash ? strlen(lastslash) : 1 + strlen(path)) + 1);
+ if (ret == NULL) {
+ rrd_set_error("cannot allocate memory");
+ free(dir_path);
+ return NULL;
+ }
+
+ strcpy(ret, dir_path);
+ if (lastslash != NULL) {
+ strcat(ret, lastslash);
} else {
- if (lastslash != NULL) {
- strcat(buffer, lastslash);
- } else {
- strcat(buffer, "/");
- strcat(buffer, path);
- }
- if (resolved_path == NULL) {
- ret = strdup(buffer);
- } else {
- strcpy(resolved_path, buffer);
- ret = resolved_path;
- }
+ strcat(ret, "/");
+ strcat(ret, path);
}
+ free(dir_path);
} else {
// out of memory
rrd_set_error("cannot allocate memory");
}
else
{
- if (*path == '/') /* not absolute path */
+ if (*path == '/') /* absolute path */
{
/* if we are stripping, then check and remove the head */
if (strip) {
path += len;
while (*path == '/')
path++;
- return path;
+ return strdup(path);
}
} else
rrd_set_error ("absolute path names not allowed when talking "
}
}
- return path;
+ return strdup(path);
} /* }}} char *get_path */
static size_t strsplit (char *string, char **fields, size_t size) /* {{{ */
rrdc_response_t *res;
int status;
int i;
- char file_path[PATH_MAX];
+ char *file_path;
memset (buffer, 0, sizeof (buffer));
buffer_ptr = &buffer[0];
return (ENOBUFS);
mutex_lock (&lock);
- filename = get_path (filename, file_path);
- if (filename == NULL)
+ file_path = get_path (filename);
+ if (file_path == NULL)
{
mutex_unlock (&lock);
return (-1);
}
- status = buffer_add_string (filename, &buffer_ptr, &buffer_free);
+ status = buffer_add_string (file_path, &buffer_ptr, &buffer_free);
+ free (file_path);
+
if (status != 0)
{
mutex_unlock (&lock);
size_t buffer_size;
rrdc_response_t *res;
int status;
- char file_path[PATH_MAX];
+ char *file_path;
if (filename == NULL)
return (-1);
return (ENOBUFS);
mutex_lock (&lock);
- filename = get_path (filename, file_path);
- if (filename == NULL)
+ file_path = get_path (filename);
+ if (file_path == NULL)
{
mutex_unlock (&lock);
return (-1);
}
- status = buffer_add_string (filename, &buffer_ptr, &buffer_free);
+ status = buffer_add_string (file_path, &buffer_ptr, &buffer_free);
+ free (file_path);
+
if (status != 0)
{
mutex_unlock (&lock);
status = res->status;
response_free (res);
-
return (status);
} /* }}} int rrdc_flush */
size_t buffer_size;
rrdc_response_t *res;
int status;
- char file_path[PATH_MAX];
+ char *file_path;
rrd_info_t *data = NULL, *cd;
rrd_infoval_t info;
unsigned int l;
}
mutex_lock (&lock);
- filename = get_path (filename, file_path);
- if (filename == NULL)
+ file_path = get_path (filename);
+ if (file_path == NULL)
{
mutex_unlock (&lock);
return (NULL);
}
- status = buffer_add_string (filename, &buffer_ptr, &buffer_free);
+ status = buffer_add_string (file_path, &buffer_ptr, &buffer_free);
+ free (file_path);
+
if (status != 0)
{
mutex_unlock (&lock);
size_t buffer_size;
rrdc_response_t *res;
int status;
- char file_path[PATH_MAX];
+ char *file_path;
time_t lastup;
if (filename == NULL) {
}
mutex_lock (&lock);
- filename = get_path (filename, file_path);
- if (filename == NULL)
+ file_path = get_path (filename);
+ if (file_path == NULL)
{
mutex_unlock (&lock);
return (-1);
}
- status = buffer_add_string (filename, &buffer_ptr, &buffer_free);
+ status = buffer_add_string (file_path, &buffer_ptr, &buffer_free);
+ free (file_path);
+
if (status != 0)
{
mutex_unlock (&lock);
size_t buffer_size;
rrdc_response_t *res;
int status;
- char file_path[PATH_MAX];
+ char *file_path;
time_t firstup;
if (filename == NULL) {
}
mutex_lock (&lock);
- filename = get_path (filename, file_path);
- if (filename == NULL)
+ file_path = get_path (filename);
+ if (file_path == NULL)
{
mutex_unlock (&lock);
return (-1);
}
- status = buffer_add_string (filename, &buffer_ptr, &buffer_free);
+ status = buffer_add_string (file_path, &buffer_ptr, &buffer_free);
+ free(file_path);
+
if (status != 0)
{
mutex_unlock (&lock);
size_t buffer_size;
rrdc_response_t *res;
int status;
- char file_path[PATH_MAX];
+ char *file_path;
int i;
if (filename == NULL) {
}
mutex_lock (&lock);
- filename = get_path (filename, file_path);
- if (filename == NULL)
+ file_path = get_path (filename);
+ if (file_path == NULL)
{
mutex_unlock (&lock);
return (-1);
}
- status = buffer_add_string (filename, &buffer_ptr, &buffer_free);
+ status = buffer_add_string (file_path, &buffer_ptr, &buffer_free);
+ free (file_path);
+
if (last_up >= 0) {
status = buffer_add_string ("-b", &buffer_ptr, &buffer_free);
status = buffer_add_ulong (last_up, &buffer_ptr, &buffer_free);
rrd_set_error ("rrdc_create: out of memory");
return (-1);
}
- }
+ }
}
/* buffer ready to send? */
size_t buffer_free;
size_t buffer_size;
rrdc_response_t *res;
- char path_buffer[PATH_MAX];
- const char *path_ptr;
+ char *file_path;
char *str_tmp;
unsigned long flush_version;
return (ENOBUFS);
/* change to path for rrdcached */
- path_ptr = get_path (filename, path_buffer);
- if (path_ptr == NULL)
+ file_path = get_path (filename);
+ if (file_path == NULL)
return (EINVAL);
- status = buffer_add_string (path_ptr, &buffer_ptr, &buffer_free);
+ status = buffer_add_string (file_path, &buffer_ptr, &buffer_free);
+ free (file_path);
+
if (status != 0)
return (ENOBUFS);