Merge remote-tracking branch 'github/pr/1749'
[collectd.git] / src / daemon / common.c
index e2c872c..3d1420d 100644 (file)
 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);