X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdaemon%2Fcommon.c;h=3d1420d62da20c5d5b8f1b02ed1f1acfa719f529;hb=92860d61218a3da1e9b74a2fad37e9df88df8ce8;hp=e2c872cc1ce819d562e5063f40e261c98cd43b19;hpb=10139cda6f68ae1f921d79c930dd85944afb74a3;p=collectd.git diff --git a/src/daemon/common.c b/src/daemon/common.c index e2c872cc..3d1420d6 100644 --- a/src/daemon/common.c +++ b/src/daemon/common.c @@ -68,6 +68,11 @@ extern kstat_ctl_t *kc; #endif +/* AIX doesn't have MSG_DONTWAIT */ +#ifndef MSG_DONTWAIT +# define MSG_DONTWAIT MSG_NONBLOCK +#endif + #if !HAVE_GETPWNAM_R static pthread_mutex_t getpwnam_r_lock = PTHREAD_MUTEX_INITIALIZER; #endif @@ -1011,7 +1016,8 @@ int format_values (char *ret, size_t ret_len, /* {{{ */ int parse_identifier (char *str, char **ret_host, char **ret_plugin, char **ret_plugin_instance, - char **ret_type, char **ret_type_instance) + char **ret_type, char **ret_type_instance, + char *default_host) { char *hostname = NULL; char *plugin = NULL; @@ -1030,8 +1036,19 @@ int parse_identifier (char *str, char **ret_host, type = strchr (plugin, '/'); if (type == NULL) - return (-1); - *type = '\0'; type++; + { + if (default_host == NULL) + return (-1); + /* else: no host specified; use default */ + type = plugin; + plugin = hostname; + hostname = default_host; + } + else + { + *type = '\0'; + type++; + } plugin_instance = strchr (plugin, '-'); if (plugin_instance != NULL) @@ -1072,7 +1089,8 @@ int parse_identifier_vl (const char *str, value_list_t *vl) /* {{{ */ status = parse_identifier (str_copy, &host, &plugin, &plugin_instance, - &type, &type_instance); + &type, &type_instance, + /* default_host = */ NULL); if (status != 0) return (status); @@ -1134,7 +1152,7 @@ int parse_value (const char *value_orig, value_t *ret_value, int ds_type) } if (value == endptr) { - ERROR ("parse_value: Failed to parse string as %s: %s.", + ERROR ("parse_value: Failed to parse string as %s: \"%s\".", DS_TYPE_TO_STRING (ds_type), value); sfree (value); return -1; @@ -1211,10 +1229,20 @@ int parse_values (char *buffer, value_list_t *vl, const data_set_t *ds) int parse_value_file (char const *path, value_t *ret_value, int ds_type) { + FILE *fh; char buffer[256]; - if (read_file_contents (path, buffer, sizeof (buffer)) < 0) - return errno; + fh = fopen (path, "r"); + if (fh == NULL) + return (-1); + + if (fgets (buffer, sizeof (buffer), fh) == NULL) + { + fclose (fh); + return (-1); + } + + fclose (fh); strstripnewline (buffer);