From d5102d959fce145c0fac926517a946290bee1124 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Thu, 3 Jul 2008 14:32:12 +0200 Subject: [PATCH] src/rrd_daemon.c: Don't close the socket if UPDATE fails. --- src/rrd_daemon.c | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/src/rrd_daemon.c b/src/rrd_daemon.c index ac974ed..f912add 100644 --- a/src/rrd_daemon.c +++ b/src/rrd_daemon.c @@ -836,6 +836,7 @@ static int handle_request_stats (int fd, /* {{{ */ RRDD_STATS_SEND; return (0); +#undef RRDD_STATS_SEND } /* }}} int handle_request_stats */ static int handle_request_flush (int fd, /* {{{ */ @@ -887,13 +888,25 @@ static int handle_request_update (int fd, /* {{{ */ cache_item_t *ci; char answer[4096]; +#define RRDD_UPDATE_SEND \ + answer[sizeof (answer) - 1] = 0; \ + status = swrite (fd, answer, strlen (answer)); \ + if (status < 0) \ + { \ + status = errno; \ + RRDD_LOG (LOG_INFO, "handle_request_update: swrite returned an error."); \ + return (status); \ + } + now = time (NULL); status = buffer_get_field (&buffer, &buffer_size, &file); if (status != 0) { - RRDD_LOG (LOG_INFO, "handle_request_update: Cannot get file name."); - return (-1); + strncpy (answer, "-1 Usage: UPDATE [ ...]\n", + sizeof (answer)); + RRDD_UPDATE_SEND; + return (0); } pthread_mutex_lock (&cache_lock); @@ -906,7 +919,10 @@ static int handle_request_update (int fd, /* {{{ */ { pthread_mutex_unlock (&cache_lock); RRDD_LOG (LOG_ERR, "handle_request_update: malloc failed."); - return (-1); + + strncpy (answer, "-1 malloc failed.\n", sizeof (answer)); + RRDD_UPDATE_SEND; + return (0); } memset (ci, 0, sizeof (cache_item_t)); @@ -914,9 +930,12 @@ static int handle_request_update (int fd, /* {{{ */ if (ci->file == NULL) { pthread_mutex_unlock (&cache_lock); - RRDD_LOG (LOG_ERR, "handle_request_update: malloc failed."); free (ci); - return (-1); + RRDD_LOG (LOG_ERR, "handle_request_update: strdup failed."); + + strncpy (answer, "-1 strdup failed.\n", sizeof (answer)); + RRDD_UPDATE_SEND; + return (0); } ci->values = NULL; @@ -973,19 +992,18 @@ static int handle_request_update (int fd, /* {{{ */ pthread_mutex_unlock (&cache_lock); - snprintf (answer, sizeof (answer), "0 Enqueued %i value%s\n", values_num, - (values_num == 1) ? "" : "s"); - answer[sizeof (answer) - 1] = 0; - - status = swrite (fd, answer, strlen (answer)); - if (status < 0) + if (values_num < 1) { - status = errno; - RRDD_LOG (LOG_INFO, "handle_request_update: swrite returned an error."); - return (status); + strncpy (answer, "-1 No values updated.\n", sizeof (answer)); } - + else + { + snprintf (answer, sizeof (answer), "0 Enqueued %i value%s\n", values_num, + (values_num == 1) ? "" : "s"); + } + RRDD_UPDATE_SEND; return (0); +#undef RRDD_UPDATE_SEND } /* }}} int handle_request_update */ static int handle_request (int fd) /* {{{ */ -- 2.11.0