From: Florian Forster Date: Tue, 5 Jan 2010 10:54:52 +0000 (+0100) Subject: Merge branch 'collectd-4.9' X-Git-Tag: collectd-4.10.0~77 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=13da81f864686e51b41a088edb63fd47d57806bd;hp=3ae8778a363fc4383f1135ae99b389fad96978f3;p=collectd.git Merge branch 'collectd-4.9' --- diff --git a/src/battery.c b/src/battery.c index b62ad81d..4178d8b5 100644 --- a/src/battery.c +++ b/src/battery.c @@ -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]; diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index e2cb799e..9af1ff51 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -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 I|I + +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, i.e. by default hidden files and directories are ignored. + =back =head2 Plugin C diff --git a/src/common.c b/src/common.c index c6a651dc..3695a9b7 100644 --- a/src/common.c +++ b/src/common.c @@ -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) diff --git a/src/common.h b/src/common.h index 019e8b69..2d5c7945 100644 --- a/src/common.h +++ b/src/common.h @@ -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); diff --git a/src/filecount.c b/src/filecount.c index 05bb4b37..47f99e91 100644 --- a/src/filecount.c +++ b/src/filecount.c @@ -32,6 +32,7 @@ #include #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); diff --git a/src/meta_data.c b/src/meta_data.c index 3a3f5e79..6a336c4b 100644 --- a/src/meta_data.c +++ b/src/meta_data.c @@ -26,15 +26,6 @@ #include /* - * 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; diff --git a/src/meta_data.h b/src/meta_data.h index 8e5a7852..9ef7b0a8 100644 --- a/src/meta_data.h +++ b/src/meta_data.h @@ -24,6 +24,15 @@ #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, diff --git a/src/thermal.c b/src/thermal.c index 2b708052..b9d07bf5 100644 --- a/src/thermal.c +++ b/src/thermal.c @@ -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)