summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cfbfca1)
raw | patch | inline | side by side (parent: cfbfca1)
author | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Sat, 9 Oct 2010 09:50:44 +0000 (09:50 +0000) | ||
committer | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Sat, 9 Oct 2010 09:50:44 +0000 (09:50 +0000) |
This fixes defect #278 (unknown commands from Solaris client). -- kevin brintnall
git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.4@2135 a5681a0c-68f1-0310-ab6d-d61299d08faa
git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.4@2135 a5681a0c-68f1-0310-ab6d-d61299d08faa
program/src/rrd_client.c | patch | blob | history |
index 187afb224c3082f0a5c6d6f40fccf5ea6ea1bc33..47333df099a1495737e4fb4afdbee6986d6d93db 100644 (file)
--- a/program/src/rrd_client.c
+++ b/program/src/rrd_client.c
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) {
- close_connection();
- return (-3);
- }
+ if (buffer_ptr == NULL)
+ DIE(-3);
+
chomp (buffer);
ret->status = strtol (buffer, &ret->message, 0);
if (buffer == ret->message)
- {
- response_free (ret);
- close_connection();
- 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);
- close_connection();
- 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);
- close_connection();
- return (-6);
- }
+ DIE(-6);
+
chomp (buffer);
ret->lines[i] = strdup (buffer);
if (ret->lines[i] == NULL)
- {
- response_free (ret);
- close_connection();
- 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, /* {{{ */