Merge branch 'collectd-4.9'
authorFlorian Forster <octo@huhu.verplant.org>
Tue, 5 Jan 2010 10:48:07 +0000 (11:48 +0100)
committerFlorian Forster <octo@huhu.verplant.org>
Tue, 5 Jan 2010 10:48:07 +0000 (11:48 +0100)
src/battery.c
src/collectd.conf.pod
src/common.c
src/common.h
src/filecount.c
src/meta_data.c
src/meta_data.h
src/thermal.c

index b62ad81..4178d8b 100644 (file)
@@ -514,7 +514,8 @@ static int battery_read (void)
 
        if (0 == access (battery_acpi_dir, R_OK))
                walk_directory (battery_acpi_dir, battery_read_acpi,
-                               /* user_data = */ NULL);
+                               /* user_data = */ NULL,
+                               /* include hidden */ 0);
        else
        {
                char errbuf[1024];
index e2cb799..9af1ff5 100644 (file)
@@ -1104,6 +1104,12 @@ note that there are 1000 bytes in a kilobyte, not 1024.
 
 Controls whether or not to recurse into subdirectories. Enabled by default.
 
+=item B<IncludeHidden> I<true>|I<false>
+
+Controls whether or not to include "hidden" files and directories in the count.
+"Hidden" files and directories are those, whose name begins with a dot.
+Defaults to I<false>, i.e. by default hidden files and directories are ignored.
+
 =back
 
 =head2 Plugin C<GenericJMX>
index c6a651d..3695a9b 100644 (file)
@@ -1008,7 +1008,7 @@ int notification_init (notification_t *n, int severity, const char *message,
 } /* int notification_init */
 
 int walk_directory (const char *dir, dirwalk_callback_f callback,
-               void *user_data)
+               void *user_data, int include_hidden)
 {
        struct dirent *ent;
        DIR *dh;
@@ -1029,9 +1029,18 @@ int walk_directory (const char *dir, dirwalk_callback_f callback,
        while ((ent = readdir (dh)) != NULL)
        {
                int status;
-
-               if (ent->d_name[0] == '.')
-                       continue;
+               
+               if (include_hidden)
+               {
+                       if ((strcmp (".", ent->d_name) == 0)
+                                       || (strcmp ("..", ent->d_name) == 0))
+                               continue;
+               }
+               else /* if (!include_hidden) */
+               {
+                       if (ent->d_name[0]=='.')
+                               continue;
+               }
 
                status = (*callback) (dir, ent->d_name, user_data);
                if (status != 0)
index 019e8b6..2d5c794 100644 (file)
@@ -280,7 +280,7 @@ int notification_init (notification_t *n, int severity, const char *message,
 typedef int (*dirwalk_callback_f)(const char *dirname, const char *filename,
                void *user_data);
 int walk_directory (const char *dir, dirwalk_callback_f callback,
-               void *user_data);
+               void *user_data, int hidden);
 int read_file_contents (const char *filename, char *buf, int bufsize);
 
 counter_t counter_diff (counter_t old_value, counter_t new_value);
index 05bb4b3..47f99e9 100644 (file)
@@ -32,6 +32,7 @@
 #include <fnmatch.h>
 
 #define FC_RECURSIVE 1
+#define FC_HIDDEN 2
 
 struct fc_directory_conf_s
 {
@@ -310,8 +311,8 @@ static int fc_config_add_dir_size (fc_directory_conf_t *dir,
   return (0);
 } /* int fc_config_add_dir_size */
 
-static int fc_config_add_dir_recursive (fc_directory_conf_t *dir,
-    oconfig_item_t *ci)
+static int fc_config_add_dir_option (fc_directory_conf_t *dir,
+    oconfig_item_t *ci, int bit)
 {
   if ((ci->values_num != 1)
       || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
@@ -322,12 +323,12 @@ static int fc_config_add_dir_recursive (fc_directory_conf_t *dir,
   }
 
   if (ci->values[0].value.boolean)
-    dir->options |= FC_RECURSIVE;
+    dir->options |= bit;
   else
-    dir->options &= ~FC_RECURSIVE;
+    dir->options &= ~bit;
 
   return (0);
-} /* int fc_config_add_dir_recursive */
+} /* int fc_config_add_dir_option */
 
 static int fc_config_add_dir (oconfig_item_t *ci)
 {
@@ -380,7 +381,9 @@ static int fc_config_add_dir (oconfig_item_t *ci)
     else if (strcasecmp ("Size", option->key) == 0)
       status = fc_config_add_dir_size (dir, option);
     else if (strcasecmp ("Recursive", option->key) == 0)
-      status = fc_config_add_dir_recursive (dir, option);
+      status = fc_config_add_dir_option (dir, option, FC_RECURSIVE);
+    else if (strcasecmp ("IncludeHidden", option->key) == 0)
+      status = fc_config_add_dir_option (dir, option, FC_HIDDEN);
     else
     {
       WARNING ("filecount plugin: fc_config_add_dir: "
@@ -475,7 +478,8 @@ static int fc_read_dir_callback (const char *dirname, const char *filename,
 
   if (S_ISDIR (statbuf.st_mode) && (dir->options & FC_RECURSIVE))
   {
-    status = walk_directory (abs_path, fc_read_dir_callback, dir);
+    status = walk_directory (abs_path, fc_read_dir_callback, dir,
+        /* include hidden = */ (dir->options & FC_HIDDEN) ? 1 : 0);
     return (status);
   }
   else if (!S_ISREG (statbuf.st_mode))
@@ -537,8 +541,9 @@ static int fc_read_dir (fc_directory_conf_t *dir)
 
   if (dir->mtime != 0)
     dir->now = time (NULL);
-
-  status = walk_directory (dir->path, fc_read_dir_callback, dir);
+    
+  status = walk_directory (dir->path, fc_read_dir_callback, dir,
+      /* include hidden */ (dir->options & FC_HIDDEN) ? 1 : 0);
   if (status != 0)
   {
     WARNING ("filecount plugin: walk_directory (%s) failed.", dir->path);
index 3a3f5e7..6a336c4 100644 (file)
 #include <pthread.h>
 
 /*
- * Defines
- */
-#define MD_TYPE_STRING       1
-#define MD_TYPE_SIGNED_INT   2
-#define MD_TYPE_UNSIGNED_INT 3
-#define MD_TYPE_DOUBLE       4
-#define MD_TYPE_BOOLEAN      5
-
-/*
  * Data types
  */
 union meta_value_u
@@ -249,6 +240,49 @@ int meta_data_exists (meta_data_t *md, const char *key) /* {{{ */
   return (0);
 } /* }}} int meta_data_exists */
 
+int meta_data_type (meta_data_t *md, const char *key) /* {{{ */
+{
+  meta_entry_t *e;
+
+  if ((md == NULL) || (key == NULL))
+    return -EINVAL;
+
+  pthread_mutex_lock (&md->lock);
+
+  for (e = md->head; e != NULL; e = e->next)
+  {
+    if (strcasecmp (key, e->key) == 0)
+    {
+      pthread_mutex_unlock (&md->lock);
+      return e->type;
+    }
+  }
+
+  pthread_mutex_unlock (&md->lock);
+  return 0;
+} /* }}} int meta_data_type */
+
+int meta_data_toc (meta_data_t *md, char ***toc) /* {{{ */
+{
+  int i = 0, count = 0;
+  meta_entry_t *e;
+
+  if ((md == NULL) || (toc == NULL))
+    return -EINVAL;
+
+  pthread_mutex_lock (&md->lock);
+
+  for (e = md->head; e != NULL; e = e->next)
+    ++count;    
+
+  *toc = malloc(count * sizeof(**toc));
+  for (e = md->head; e != NULL; e = e->next)
+    (*toc)[i++] = strdup(e->key);
+  
+  pthread_mutex_unlock (&md->lock);
+  return count;
+} /* }}} int meta_data_toc */
+
 int meta_data_delete (meta_data_t *md, const char *key) /* {{{ */
 {
   meta_entry_t *this;
index 8e5a785..9ef7b0a 100644 (file)
 
 #include "collectd.h"
 
+/*
+ * Defines
+ */
+#define MD_TYPE_STRING       1
+#define MD_TYPE_SIGNED_INT   2
+#define MD_TYPE_UNSIGNED_INT 3
+#define MD_TYPE_DOUBLE       4
+#define MD_TYPE_BOOLEAN      5
+
 struct meta_data_s;
 typedef struct meta_data_s meta_data_t;
 
@@ -31,6 +40,8 @@ meta_data_t *meta_data_create (void);
 void meta_data_destroy (meta_data_t *md);
 
 int meta_data_exists (meta_data_t *md, const char *key);
+int meta_data_type (meta_data_t *md, const char *key);
+int meta_data_toc (meta_data_t *md, char ***toc);
 int meta_data_delete (meta_data_t *md, const char *key);
 
 int meta_data_add_string (meta_data_t *md,
index 2b70805..b9d07bf 100644 (file)
@@ -218,13 +218,13 @@ static int thermal_config (const char *key, const char *value)
 static int thermal_sysfs_read (void)
 {
        return walk_directory (dirname_sysfs, thermal_sysfs_device_read,
-                       /* user_data = */ NULL);
+                       /* user_data = */ NULL, /* include hidden */ 0);
 }
 
 static int thermal_procfs_read (void)
 {
        return walk_directory (dirname_procfs, thermal_procfs_device_read,
-                       /* user_data = */ NULL);
+                       /* user_data = */ NULL, /* include hidden */ 0);
 }
 
 static int thermal_init (void)