X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcommon.c;h=406482ad6a84c5d13642d4a0f8b5bb5909b01434;hb=76a7816d2c066f2feff5c77e7da58df4dbc982c2;hp=6fdb441c95af1ed952267d674e8d7f240f289dc5;hpb=0f5d1ee8c3fc787df12d72dfe1bbedaa9e80ed5f;p=collectd.git diff --git a/src/common.c b/src/common.c index 6fdb441c..406482ad 100644 --- a/src/common.c +++ b/src/common.c @@ -543,11 +543,12 @@ int check_create_dir (const char *file_orig) } while (42) { - if (stat (dir, &statbuf) == -1) + if ((stat (dir, &statbuf) == -1) + && (lstat (dir, &statbuf) == -1)) { if (errno == ENOENT) { - if (mkdir (dir, 0755) == 0) + if (mkdir (dir, S_IRWXU | S_IRWXG | S_IRWXO) == 0) break; /* this might happen, if a different thread created @@ -939,22 +940,38 @@ int parse_identifier_vl (const char *str, value_list_t *vl) /* {{{ */ if (status != 0) return (status); - sstrncpy (vl->host, host, sizeof (host)); - sstrncpy (vl->plugin, plugin, sizeof (plugin)); + sstrncpy (vl->host, host, sizeof (vl->host)); + sstrncpy (vl->plugin, plugin, sizeof (vl->plugin)); sstrncpy (vl->plugin_instance, (plugin_instance != NULL) ? plugin_instance : "", - sizeof (plugin_instance)); - sstrncpy (vl->type, type, sizeof (type)); + sizeof (vl->plugin_instance)); + sstrncpy (vl->type, type, sizeof (vl->type)); sstrncpy (vl->type_instance, (type_instance != NULL) ? type_instance : "", - sizeof (type_instance)); + sizeof (vl->type_instance)); return (0); } /* }}} int parse_identifier_vl */ -int parse_value (const char *value, value_t *ret_value, int ds_type) +int parse_value (const char *value_orig, value_t *ret_value, int ds_type) { + char *value; char *endptr = NULL; + size_t value_len; + + if (value_orig == NULL) + return (EINVAL); + + value = strdup (value_orig); + if (value == NULL) + return (ENOMEM); + value_len = strlen (value); + + while ((value_len > 0) && isspace ((int) value[value_len - 1])) + { + value[value_len - 1] = 0; + value_len--; + } switch (ds_type) { @@ -975,17 +992,23 @@ int parse_value (const char *value, value_t *ret_value, int ds_type) break; default: + sfree (value); ERROR ("parse_value: Invalid data source type: %i.", ds_type); return -1; } if (value == endptr) { - ERROR ("parse_value: Failed to parse string as number: %s.", value); + sfree (value); + ERROR ("parse_value: Failed to parse string as %s: %s.", + DS_TYPE_TO_STRING (ds_type), value); return -1; } else if ((NULL != endptr) && ('\0' != *endptr)) - WARNING ("parse_value: Ignoring trailing garbage after number: %s.", - endptr); + INFO ("parse_value: Ignoring trailing garbage \"%s\" after %s value. " + "Input string was \"%s\".", + endptr, DS_TYPE_TO_STRING (ds_type), value_orig); + + sfree (value); return 0; } /* int parse_value */