Removed the `XXX_HAVE_READ' defines from all plugins.
[collectd.git] / src / unixsock.c
index 215abdd..82c15a8 100644 (file)
@@ -36,7 +36,7 @@
 # define UNIX_PATH_MAX sizeof (((struct sockaddr_un *)0)->sun_path)
 #endif
 
-#define US_DEFAULT_PATH PREFIX"/var/run/"PACKAGE_NAME"-unixsock"
+#define US_DEFAULT_PATH LOCALSTATEDIR"/run/"PACKAGE_NAME"-unixsock"
 
 /*
  * Private data structures
@@ -329,7 +329,7 @@ static void cache_flush (int max_age)
        } /* while (this != NULL) */
 
        pthread_mutex_unlock (&cache_lock);
-} /* int cache_flush */
+} /* void cache_flush */
 
 static int us_open_socket (void)
 {
@@ -630,6 +630,56 @@ static int us_handle_putval (FILE *fh, char **fields, int fields_num)
        return (0);
 } /* int us_handle_putval */
 
+static int us_handle_listval (FILE *fh, char **fields, int fields_num)
+{
+       char buffer[1024];
+       char **value_list = NULL;
+       int value_list_len = 0;
+       value_cache_t *entry;
+       int i;
+
+       if (fields_num != 1)
+       {
+               DEBUG ("unixsock plugin: us_handle_listval: "
+                               "Wrong number of fields: %i", fields_num);
+               fprintf (fh, "-1 Wrong number of fields: Got %i, expected 1.\n",
+                               fields_num);
+               fflush (fh);
+               return (-1);
+       }
+
+       pthread_mutex_lock (&cache_lock);
+
+       for (entry = cache_head; entry != NULL; entry = entry->next)
+       {
+               char **tmp;
+
+               snprintf (buffer, sizeof (buffer), "%u %s\n",
+                               (unsigned int) entry->time, entry->name);
+               buffer[sizeof (buffer) - 1] = '\0';
+               
+               tmp = realloc (value_list, sizeof (char *) * (value_list_len + 1));
+               if (tmp == NULL)
+                       continue;
+               value_list = tmp;
+
+               value_list[value_list_len] = strdup (buffer);
+
+               if (value_list[value_list_len] != NULL)
+                       value_list_len++;
+       } /* for (entry) */
+
+       pthread_mutex_unlock (&cache_lock);
+
+       DEBUG ("unixsock plugin: us_handle_listval: value_list_len = %i", value_list_len);
+       fprintf (fh, "%i Values found\n", value_list_len);
+       for (i = 0; i < value_list_len; i++)
+               fputs (value_list[i], fh);
+       fflush (fh);
+
+       return (0);
+} /* int us_handle_listval */
+
 static void *us_handle_client (void *arg)
 {
        int fd;
@@ -685,6 +735,10 @@ static void *us_handle_client (void *arg)
                {
                        us_handle_putval (fh, fields, fields_num);
                }
+               else if (strcasecmp (fields[0], "listval") == 0)
+               {
+                       us_handle_listval (fh, fields, fields_num);
+               }
                else
                {
                        fprintf (fh, "-1 Unknown command: %s\n", fields[0]);