diff --git a/src/common.c b/src/common.c
index 0069a8b6508691b4fd2270642d10452428606fc4..0bd9f68fe84a751c339cc9b652c0587d9aa7273b 100644 (file)
--- a/src/common.c
+++ b/src/common.c
{
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
kstat_named_t *kn;
long long retval = -1LL;
-#ifdef assert
- assert (ksp != NULL);
- assert (ksp->ks_type == KSTAT_TYPE_NAMED);
-#else
if (ksp == NULL)
{
- ERROR ("ERROR: %s:%i: ksp == NULL\n", __FILE__, __LINE__);
+ ERROR ("get_kstat_value (\"%s\"): ksp is NULL.", name);
return (-1LL);
}
else if (ksp->ks_type != KSTAT_TYPE_NAMED)
{
- ERROR ("ERROR: %s:%i: ksp->ks_type != KSTAT_TYPE_NAMED\n", __FILE__, __LINE__);
+ ERROR ("get_kstat_value (\"%s\"): ksp->ks_type (%#x) "
+ "is not KSTAT_TYPE_NAMED (%#x).",
+ name,
+ (unsigned int) ksp->ks_type,
+ (unsigned int) KSTAT_TYPE_NAMED);
return (-1LL);
}
-#endif
if ((kn = (kstat_named_t *) kstat_data_lookup (ksp, name)) == NULL)
- return (retval);
+ return (-1LL);
if (kn->data_type == KSTAT_DATA_INT32)
retval = (long long) kn->value.i32;
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)
{
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;
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 */