[collectd] [PATCH] filecount plugin: add the possibility to specify more than one Name
Moritz Orbach
ml-collectd at apfelboymchen.homeunix.net
Sun May 19 11:24:36 CEST 2013
Signed-off-by: Moritz Orbach <ml-collectd at apfelboymchen.homeunix.net>
---
src/collectd.conf.pod | 10 +++++++---
src/filecount.c | 37 ++++++++++++++++++++++++++++---------
2 files changed, 35 insertions(+), 12 deletions(-)
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index c5d4f19..a61ba6b 100644
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
@@ -1676,9 +1676,13 @@ and all leading underscores removed.
=item B<Name> I<Pattern>
Only count files that match I<Pattern>, where I<Pattern> is a shell-like
-wildcard as understood by L<fnmatch(3)>. Only the B<filename> is checked
-against the pattern, not the entire path. In case this makes it easier for you:
-This option has been named after the B<-name> parameter to L<find(1)>.
+wildcard as understood by L<fnmatch(3)>. This option can be specified multiple
+times to match filenames against multiple I<Pattern>s. If it is not specified,
+all files will be counted.
+
+Only the B<filename> is checked against the pattern, not the entire path. In
+case this makes it easier for you: This option has been named after the
+B<-name> parameter to L<find(1)>.
=item B<MTime> I<Age>
diff --git a/src/filecount.c b/src/filecount.c
index 47f99e9..bcd9206 100644
--- a/src/filecount.c
+++ b/src/filecount.c
@@ -46,12 +46,15 @@ struct fc_directory_conf_s
uint64_t files_size;
/* Selectors */
- char *name;
+ char **names;
int64_t mtime;
int64_t size;
/* Helper for the recursive functions */
time_t now;
+
+ /* Helper for multiple globs */
+ size_t names_num;
};
typedef struct fc_directory_conf_s fc_directory_conf_t;
@@ -157,8 +160,16 @@ static int fc_config_add_dir_name (fc_directory_conf_t *dir,
return (-1);
}
- sfree (dir->name);
- dir->name = temp;
+ char **names_temp;
+ names_temp = realloc (dir->names, (dir->names_num + 1) * sizeof *dir->names);
+ if (names_temp == NULL)
+ {
+ ERROR ("filecount plugin: realloc failed.");
+ return (-1);
+ }
+ dir->names_num++;
+ dir->names = names_temp;
+ dir->names[dir->names_num - 1] = temp;
return (0);
} /* int fc_config_add_dir_name */
@@ -363,7 +374,8 @@ static int fc_config_add_dir (oconfig_item_t *ci)
dir->options = FC_RECURSIVE;
- dir->name = NULL;
+ dir->names = NULL;
+ dir->names_num = 0;
dir->mtime = 0;
dir->size = 0;
@@ -416,7 +428,10 @@ static int fc_config_add_dir (oconfig_item_t *ci)
if (status != 0)
{
- sfree (dir->name);
+ for (i = 0; i < dir->names_num; i++) {
+ sfree (dir->names[i]);
+ }
+ sfree (dir->names);
sfree (dir->instance);
sfree (dir->path);
sfree (dir);
@@ -463,6 +478,7 @@ static int fc_read_dir_callback (const char *dirname, const char *filename,
char abs_path[PATH_MAX];
struct stat statbuf;
int status;
+ int i;
if (dir == NULL)
return (-1);
@@ -487,12 +503,15 @@ static int fc_read_dir_callback (const char *dirname, const char *filename,
return (0);
}
- if (dir->name != NULL)
+ for (i = 0; i < dir->names_num; i++)
{
- status = fnmatch (dir->name, filename, /* flags = */ 0);
- if (status != 0)
- return (0);
+ status = fnmatch (dir->names[i], filename, /* flags = */ 0);
+ if (status == 0)
+ /* match */
+ break;
}
+ if (status != 0)
+ return (0);
if (dir->mtime != 0)
{
--
1.8.1.5
More information about the collectd
mailing list