X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Futils_cmd_getval.c;h=657483b6cf35c6f00bf62afc3e3c71a7c55c0f2f;hb=9c3ed6462c15fd1cb664cd0ec2a5efb289aa1af6;hp=33b40e09af7532a951d2611f83fe9fe2493360ee;hpb=aec20e4438a754fe2df160e01adea9f1285fe8af;p=collectd.git diff --git a/src/utils_cmd_getval.c b/src/utils_cmd_getval.c index 33b40e09..657483b6 100644 --- a/src/utils_cmd_getval.c +++ b/src/utils_cmd_getval.c @@ -27,12 +27,15 @@ #include "utils_parse_option.h" #define print_to_socket(fh, ...) \ - if (fprintf (fh, __VA_ARGS__) < 0) { \ - char errbuf[1024]; \ - WARNING ("handle_getval: failed to write to socket #%i: %s", \ - fileno (fh), sstrerror (errno, errbuf, sizeof (errbuf))); \ - return -1; \ - } + do { \ + if (fprintf (fh, __VA_ARGS__) < 0) { \ + char errbuf[1024]; \ + WARNING ("handle_getval: failed to write to socket #%i: %s", \ + fileno (fh), sstrerror (errno, errbuf, sizeof (errbuf))); \ + return -1; \ + } \ + fflush(fh); \ + } while (0) int handle_getval (FILE *fh, char *buffer) { @@ -51,7 +54,7 @@ int handle_getval (FILE *fh, char *buffer) const data_set_t *ds; int status; - int i; + size_t i; if ((fh == NULL) || (buffer == NULL)) return (-1); @@ -83,6 +86,12 @@ int handle_getval (FILE *fh, char *buffer) } assert (identifier != NULL); + if (*buffer != 0) + { + print_to_socket (fh, "-1 Garbage after end of command: %s\n", buffer); + return (-1); + } + /* parse_identifier() modifies its first argument, * returning pointers into it */ identifier_copy = sstrdup (identifier); @@ -92,7 +101,7 @@ int handle_getval (FILE *fh, char *buffer) &type, &type_instance); if (status != 0) { - DEBUG ("unixsock plugin: Cannot parse identifier `%s'.", identifier); + DEBUG ("handle_getval: Cannot parse identifier `%s'.", identifier); print_to_socket (fh, "-1 Cannot parse identifier `%s'.\n", identifier); sfree (identifier_copy); return (-1); @@ -101,7 +110,7 @@ int handle_getval (FILE *fh, char *buffer) ds = plugin_get_ds (type); if (ds == NULL) { - DEBUG ("unixsock plugin: plugin_get_ds (%s) == NULL;", type); + DEBUG ("handle_getval: plugin_get_ds (%s) == NULL;", type); print_to_socket (fh, "-1 Type `%s' is unknown.\n", type); sfree (identifier_copy); return (-1); @@ -117,7 +126,7 @@ int handle_getval (FILE *fh, char *buffer) return (-1); } - if (ds->ds_num != values_num) + if ((size_t) ds->ds_num != values_num) { ERROR ("ds[%s]->ds_num = %i, " "but uc_get_rate_by_name returned %u values.",