diff --git a/src/common.c b/src/common.c
index 1c80e8f1b8cd6d2f85dfebd482e30caf88cdf6d0..0bd9f68fe84a751c339cc9b652c0587d9aa7273b 100644 (file)
--- a/src/common.c
+++ b/src/common.c
# include <math.h>
#endif
-/* for ntohl and htonl */
-#if HAVE_ARPA_INET_H
-# include <arpa/inet.h>
-#endif
-
/* for getaddrinfo */
#include <sys/types.h>
#include <sys/socket.h>
# include <netinet/in.h>
#endif
+/* for ntohl and htonl */
+#if HAVE_ARPA_INET_H
+# include <arpa/inet.h>
+#endif
+
#ifdef HAVE_LIBKSTAT
extern kstat_ctl_t *kc;
#endif
}
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
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;
if (status != 0)
return (status);
- sstrncpy (vl->host, host, sizeof (host));
- sstrncpy (vl->plugin, plugin, sizeof (plugin));
- sstrncpy (vl->plugin_instance, plugin_instance, sizeof (plugin_instance));
- sstrncpy (vl->type, type, sizeof (type));
- sstrncpy (vl->type_instance, type_instance, sizeof (type_instance));
+ sstrncpy (vl->host, host, sizeof (vl->host));
+ sstrncpy (vl->plugin, plugin, sizeof (vl->plugin));
+ sstrncpy (vl->plugin_instance,
+ (plugin_instance != NULL) ? plugin_instance : "",
+ sizeof (vl->plugin_instance));
+ sstrncpy (vl->type, type, sizeof (vl->type));
+ sstrncpy (vl->type_instance,
+ (type_instance != NULL) ? 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)
{
break;
case DS_TYPE_DERIVE:
- ret_value->counter = (derive_t) strtoll (value, &endptr, 0);
+ ret_value->derive = (derive_t) strtoll (value, &endptr, 0);
break;
case DS_TYPE_ABSOLUTE:
- ret_value->counter = (absolute_t) strtoull (value, &endptr, 0);
+ ret_value->absolute = (absolute_t) strtoull (value, &endptr, 0);
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 */