projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'collectd-4.4'
[collectd.git]
/
src
/
utils_cmd_putval.c
diff --git
a/src/utils_cmd_putval.c
b/src/utils_cmd_putval.c
index
98b5043
..
9cbba12
100644
(file)
--- a/
src/utils_cmd_putval.c
+++ b/
src/utils_cmd_putval.c
@@
-23,8
+23,15
@@
#include "common.h"
#include "plugin.h"
#include "common.h"
#include "plugin.h"
+#define print_to_socket(fh, ...) \
+ if (fprintf (fh, __VA_ARGS__) < 0) { \
+ char errbuf[1024]; \
+ WARNING ("handle_putval: failed to write to socket #%i: %s", \
+ fileno (fh), sstrerror (errno, errbuf, sizeof (errbuf))); \
+ return -1; \
+ }
+
static int parse_value (const data_set_t *ds, value_list_t *vl,
static int parse_value (const data_set_t *ds, value_list_t *vl,
- const char *type,
FILE *fh, char *buffer)
{
char *dummy;
FILE *fh, char *buffer)
{
char *dummy;
@@
-36,7
+43,7
@@
static int parse_value (const data_set_t *ds, value_list_t *vl,
char *value_str = strchr (time_str, ':');
if (value_str == NULL)
{
char *value_str = strchr (time_str, ':');
if (value_str == NULL)
{
-
fprintf
(fh, "-1 No time found.\n");
+
print_to_socket
(fh, "-1 No time found.\n");
return (-1);
}
*value_str = '\0'; value_str++;
return (-1);
}
*value_str = '\0'; value_str++;
@@
-76,13
+83,13
@@
static int parse_value (const data_set_t *ds, value_list_t *vl,
"Number of values incorrect: "
"Got %i, expected %i. Identifier is `%s'.",
i, vl->values_len, identifier);
"Number of values incorrect: "
"Got %i, expected %i. Identifier is `%s'.",
i, vl->values_len, identifier);
-
fprintf
(fh, "-1 Number of values incorrect: "
+
print_to_socket
(fh, "-1 Number of values incorrect: "
"Got %i, expected %i.\n",
i, vl->values_len);
return (-1);
}
"Got %i, expected %i.\n",
i, vl->values_len);
return (-1);
}
- plugin_dispatch_values (
type,
vl);
+ plugin_dispatch_values (vl);
return (0);
} /* int parse_value */
return (0);
} /* int parse_value */
@@
-130,10
+137,9
@@
int handle_putval (FILE *fh, char **fields, int fields_num)
{
DEBUG ("cmd putval: Wrong number of fields: %i",
fields_num);
{
DEBUG ("cmd putval: Wrong number of fields: %i",
fields_num);
-
fprintf
(fh, "-1 Wrong number of fields: Got %i, "
+
print_to_socket
(fh, "-1 Wrong number of fields: Got %i, "
"expected at least 3.\n",
fields_num);
"expected at least 3.\n",
fields_num);
- fflush (fh);
return (-1);
}
return (-1);
}
@@
-147,8
+153,7
@@
int handle_putval (FILE *fh, char **fields, int fields_num)
if (status != 0)
{
DEBUG ("cmd putval: Cannot parse `%s'", fields[1]);
if (status != 0)
{
DEBUG ("cmd putval: Cannot parse `%s'", fields[1]);
- fprintf (fh, "-1 Cannot parse identifier.\n");
- fflush (fh);
+ print_to_socket (fh, "-1 Cannot parse identifier.\n");
sfree (identifier_copy);
return (-1);
}
sfree (identifier_copy);
return (-1);
}
@@
-160,18
+165,18
@@
int handle_putval (FILE *fh, char **fields, int fields_num)
|| ((type_instance != NULL)
&& (strlen (type_instance) >= sizeof (vl.type_instance))))
{
|| ((type_instance != NULL)
&& (strlen (type_instance) >= sizeof (vl.type_instance))))
{
- fprintf (fh, "-1 Identifier too long.\n");
- fflush (fh);
+ print_to_socket (fh, "-1 Identifier too long.\n");
sfree (identifier_copy);
return (-1);
}
sfree (identifier_copy);
return (-1);
}
- strcpy (vl.host, hostname);
- strcpy (vl.plugin, plugin);
+ sstrncpy (vl.host, hostname, sizeof (vl.host));
+ sstrncpy (vl.plugin, plugin, sizeof (vl.plugin));
+ sstrncpy (vl.type, type, sizeof (vl.type));
if (plugin_instance != NULL)
if (plugin_instance != NULL)
- s
trcpy (vl.plugin_instance, plugin_instance
);
+ s
strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)
);
if (type_instance != NULL)
if (type_instance != NULL)
- s
trcpy (vl.type_instance, type_instance
);
+ s
strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)
);
ds = plugin_get_ds (type);
if (ds == NULL) {
ds = plugin_get_ds (type);
if (ds == NULL) {
@@
-183,8
+188,7
@@
int handle_putval (FILE *fh, char **fields, int fields_num)
vl.values = (value_t *) malloc (vl.values_len * sizeof (value_t));
if (vl.values == NULL)
{
vl.values = (value_t *) malloc (vl.values_len * sizeof (value_t));
if (vl.values == NULL)
{
- fprintf (fh, "-1 malloc failed.\n");
- fflush (fh);
+ print_to_socket (fh, "-1 malloc failed.\n");
sfree (identifier_copy);
return (-1);
}
sfree (identifier_copy);
return (-1);
}
@@
-197,14
+201,14
@@
int handle_putval (FILE *fh, char **fields, int fields_num)
/* It's parse_value's job to write an error to `fh'.
* This is not the case with `parse_option below.
* Neither will write an success message. */
/* It's parse_value's job to write an error to `fh'.
* This is not the case with `parse_option below.
* Neither will write an success message. */
- if (parse_value (ds, &vl,
type,
fh, fields[i]) != 0)
+ if (parse_value (ds, &vl, fh, fields[i]) != 0)
break;
}
else if (strchr (fields[i], '=') != NULL)
{
if (parse_option (&vl, fields[i]) != 0)
{
break;
}
else if (strchr (fields[i], '=') != NULL)
{
if (parse_option (&vl, fields[i]) != 0)
{
-
fprintf
(fh, "-1 Error parsing option `%s'\n",
+
print_to_socket
(fh, "-1 Error parsing option `%s'\n",
fields[i]);
break;
}
fields[i]);
break;
}
@@
-220,8
+224,7
@@
int handle_putval (FILE *fh, char **fields, int fields_num)
/* Done parsing the options. */
if (i == fields_num)
/* Done parsing the options. */
if (i == fields_num)
- fprintf (fh, "0 Success\n");
- fflush (fh);
+ print_to_socket (fh, "0 Success\n");
sfree (vl.values);
sfree (identifier_copy);
sfree (vl.values);
sfree (identifier_copy);