*
* Authors:
* Alessandro Iurlano <alessandro.iurlano at gmail.com>
- * Florian octo Forster <octo at verplant.org>
+ * Florian octo Forster <octo at collectd.org>
**/
#include "collectd.h"
#include "common.h"
-#include "plugin.h"
+#include "plugin.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fnmatch.h>
#define FC_RECURSIVE 1
-#define FC_HIDDEN 1
+#define FC_HIDDEN 2
struct fc_directory_conf_s
{
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))
}
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 */
-
-static int fc_config_add_dir_hidden (fc_directory_conf_t *dir,
- oconfig_item_t *ci)
-{
- if ((ci->values_num != 1)
- || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
- {
- WARNING ("filecount plugin: The `Hidden' config options needs exactly "
- "one boolean argument.");
- return (-1);
- }
-
- if (ci->values[0].value.boolean)
- dir->options |= FC_HIDDEN;
- else
- dir->options &= ~FC_HIDDEN;
-
- return (0);
-} /* int fc_config_add_dir_hidden */
+} /* int fc_config_add_dir_option */
static int fc_config_add_dir (oconfig_item_t *ci)
{
}
/* Initialize `dir' */
- dir = (fc_directory_conf_t *) malloc (sizeof (*dir));
+ dir = calloc (1, sizeof (*dir));
if (dir == NULL)
{
- ERROR ("filecount plugin: malloc failed.");
+ ERROR ("filecount plugin: calloc failed.");
return (-1);
}
- memset (dir, 0, sizeof (*dir));
dir->path = strdup (ci->values[0].value.string);
if (dir->path == NULL)
{
ERROR ("filecount plugin: strdup failed.");
+ sfree (dir);
return (-1);
}
fc_config_set_instance (dir, dir->path);
dir->options = FC_RECURSIVE;
- dir->options = FC_HIDDEN;
dir->name = NULL;
dir->mtime = 0;
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);
- else if (strcasecmp ("Hidden", option->key) == 0)
- status = fc_config_add_dir_hidden (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: "
{
fc_directory_conf_t **temp;
- temp = (fc_directory_conf_t **) realloc (directories,
+ temp = realloc (directories,
sizeof (*directories) * (directories_num + 1));
if (temp == NULL)
{
if (S_ISDIR (statbuf.st_mode) && (dir->options & FC_RECURSIVE))
{
- if(dir->options & FC_HIDDEN)
- status = walk_directory (abs_path, fc_read_dir_callback, dir,/* include hidden */1);
- else
- status = walk_directory (abs_path, fc_read_dir_callback, dir,/* include hidden */ 0);
+ 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))
if (dir->mtime != 0)
dir->now = time (NULL);
-
- if(dir->options & FC_HIDDEN)
- status = walk_directory (dir->path, fc_read_dir_callback, dir,/* include hidden */ 1);
- else
- status = walk_directory (dir->path, fc_read_dir_callback, dir,/* include hidden */ 0);
+
+ 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);