diff --git a/src/rrd_client.c b/src/rrd_client.c
index 471e046fa42f3ae09849cc35c6539f7eab243e52..11c1e3357b08d18ea35140469ff82dcda53afd85 100644 (file)
--- a/src/rrd_client.c
+++ b/src/rrd_client.c
const char *ret = path;
int is_unix = 0;
+ if ((path == NULL) || (resolved_path == NULL) || (sd_path == NULL))
+ return (NULL);
+
if ((*sd_path == '/')
|| (strncmp ("unix:", sd_path, strlen ("unix:")) == 0))
is_unix = 1;
- if (*path == '/') /* absolute path */
+ if (is_unix)
{
- if (! is_unix)
- {
- rrd_set_error ("absolute path names not allowed when talking "
- "to a remote daemon");
- return (NULL);
- }
- /* else: nothing to do */
+ ret = realpath(path, resolved_path);
+ if (ret == NULL)
+ rrd_set_error("realpath(%s): %s", path, rrd_strerror(errno));
+ return ret;
}
- else /* relative path */
+ else
{
- if (is_unix)
+ if (*path == '/') /* not absolute path */
{
- realpath (path, resolved_path);
- ret = resolved_path;
+ rrd_set_error ("absolute path names not allowed when talking "
+ "to a remote daemon");
+ return NULL;
}
- /* else: nothing to do */
}
- return (ret);
+
+ return path;
} /* }}} char *get_path */
/* One must hold `lock' when calling `close_connection'. */
static int response_read (rrdc_response_t **ret_response) /* {{{ */
{
- rrdc_response_t *ret;
+ rrdc_response_t *ret = NULL;
+ int status = 0;
char buffer[4096];
char *buffer_ptr;
size_t i;
+#define DIE(code) do { status = code; goto err_out; } while(0)
+
if (sh == NULL)
- return (-1);
+ DIE(-1);
ret = (rrdc_response_t *) malloc (sizeof (rrdc_response_t));
if (ret == NULL)
- return (-2);
+ DIE(-2);
memset (ret, 0, sizeof (*ret));
ret->lines = NULL;
ret->lines_num = 0;
buffer_ptr = fgets (buffer, sizeof (buffer), sh);
if (buffer_ptr == NULL)
- return (-3);
+ DIE(-3);
+
chomp (buffer);
ret->status = strtol (buffer, &ret->message, 0);
if (buffer == ret->message)
- {
- response_free (ret);
- return (-4);
- }
+ DIE(-4);
+
/* Skip leading whitespace of the status message */
ret->message += strspn (ret->message, " \t");
{
if (ret->status < 0)
rrd_set_error("rrdcached: %s", ret->message);
- *ret_response = ret;
- return (0);
+ goto out;
}
ret->lines = (char **) malloc (sizeof (char *) * ret->status);
if (ret->lines == NULL)
- {
- response_free (ret);
- return (-5);
- }
+ DIE(-5);
+
memset (ret->lines, 0, sizeof (char *) * ret->status);
ret->lines_num = (size_t) ret->status;
{
buffer_ptr = fgets (buffer, sizeof (buffer), sh);
if (buffer_ptr == NULL)
- {
- response_free (ret);
- return (-6);
- }
+ DIE(-6);
+
chomp (buffer);
ret->lines[i] = strdup (buffer);
if (ret->lines[i] == NULL)
- {
- response_free (ret);
- return (-7);
- }
+ DIE(-7);
}
+out:
*ret_response = ret;
- return (0);
+ fflush(sh);
+ return (status);
+
+err_out:
+ response_free(ret);
+ close_connection();
+ return (status);
+
+#undef DIE
+
} /* }}} rrdc_response_t *response_read */
static int request (const char *buffer, size_t buffer_size, /* {{{ */
break;
} /* for (ai_ptr) */
+ freeaddrinfo(ai_res);
+
return (status);
} /* }}} int rrdc_connect_network */
{
int status = 0;
- if (addr == NULL)
+ if (addr == NULL) {
addr = getenv (ENV_RRDCACHED_ADDRESS);
+ }
- if (addr == NULL)
- return 0;
+ if (addr == NULL || ! strcmp(addr,"") ) {
+ addr = NULL;
+ return 0;
+ }
pthread_mutex_lock(&lock);