RRDD_STATS_SEND;
return (0);
+#undef RRDD_STATS_SEND
} /* }}} int handle_request_stats */
static int handle_request_flush (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 <filename> <values> [<values> ...]\n",
+ sizeof (answer));
+ RRDD_UPDATE_SEND;
+ return (0);
}
pthread_mutex_lock (&cache_lock);
{
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));
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;
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) /* {{{ */