X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcommon.c;h=406482ad6a84c5d13642d4a0f8b5bb5909b01434;hb=b4c8f3f762d666742c774ab3b45815e5a416e5da;hp=e1f204b9824ce05ca44a6a1861324bfcfe08747c;hpb=a24bf968e72f9a103a354dcc833619a40849cfcd;p=collectd.git diff --git a/src/common.c b/src/common.c index e1f204b9..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 @@ -952,9 +953,25 @@ int parse_identifier_vl (const char *str, value_list_t *vl) /* {{{ */ 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,11 +992,13 @@ 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) { + sfree (value); ERROR ("parse_value: Failed to parse string as %s: %s.", DS_TYPE_TO_STRING (ds_type), value); return -1; @@ -987,8 +1006,9 @@ int parse_value (const char *value, value_t *ret_value, int ds_type) else if ((NULL != endptr) && ('\0' != *endptr)) INFO ("parse_value: Ignoring trailing garbage \"%s\" after %s value. " "Input string was \"%s\".", - endptr, DS_TYPE_TO_STRING (ds_type), value); + endptr, DS_TYPE_TO_STRING (ds_type), value_orig); + sfree (value); return 0; } /* int parse_value */