projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #1646 from rubenk/cleanup-malloc-calls
[collectd.git]
/
src
/
filecount.c
diff --git
a/src/filecount.c
b/src/filecount.c
index
6899d50
..
3b5038c
100644
(file)
--- a/
src/filecount.c
+++ b/
src/filecount.c
@@
-18,7
+18,7
@@
*
* Authors:
* Alessandro Iurlano <alessandro.iurlano at gmail.com>
*
* 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 "collectd.h"
@@
-32,6
+32,7
@@
#include <fnmatch.h>
#define FC_RECURSIVE 1
#include <fnmatch.h>
#define FC_RECURSIVE 1
+#define FC_HIDDEN 2
struct fc_directory_conf_s
{
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 */
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_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)
}
if (ci->values[0].value.boolean)
- dir->options |=
FC_RECURSIVE
;
+ dir->options |=
bit
;
else
else
- dir->options &= ~
FC_RECURSIVE
;
+ dir->options &= ~
bit
;
return (0);
return (0);
-} /* int fc_config_add_dir_
recursive
*/
+} /* int fc_config_add_dir_
option
*/
static int fc_config_add_dir (oconfig_item_t *ci)
{
static int fc_config_add_dir (oconfig_item_t *ci)
{
@@
-343,18
+344,18
@@
static int fc_config_add_dir (oconfig_item_t *ci)
}
/* Initialize `dir' */
}
/* Initialize `dir' */
- dir =
(fc_directory_conf_t *) malloc (
sizeof (*dir));
+ dir =
calloc (1,
sizeof (*dir));
if (dir == NULL)
{
if (dir == NULL)
{
- ERROR ("filecount plugin:
m
alloc failed.");
+ ERROR ("filecount plugin:
c
alloc failed.");
return (-1);
}
return (-1);
}
- memset (dir, 0, sizeof (*dir));
dir->path = strdup (ci->values[0].value.string);
if (dir->path == NULL)
{
ERROR ("filecount plugin: strdup failed.");
dir->path = strdup (ci->values[0].value.string);
if (dir->path == NULL)
{
ERROR ("filecount plugin: strdup failed.");
+ sfree (dir);
return (-1);
}
return (-1);
}
@@
-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)
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: "
else
{
WARNING ("filecount plugin: fc_config_add_dir: "
@@
-476,7
+479,7
@@
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,
if (S_ISDIR (statbuf.st_mode) && (dir->options & FC_RECURSIVE))
{
status = walk_directory (abs_path, fc_read_dir_callback, dir,
- /* include hidden = */ 0);
+ /* include hidden = */
(dir->options & FC_HIDDEN) ? 1 :
0);
return (status);
}
else if (!S_ISREG (statbuf.st_mode))
return (status);
}
else if (!S_ISREG (statbuf.st_mode))
@@
-538,9
+541,9
@@
static int fc_read_dir (fc_directory_conf_t *dir)
if (dir->mtime != 0)
dir->now = time (NULL);
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
= */
0);
+ /* include hidden
*/ (dir->options & FC_HIDDEN) ? 1 :
0);
if (status != 0)
{
WARNING ("filecount plugin: walk_directory (%s) failed.", dir->path);
if (status != 0)
{
WARNING ("filecount plugin: walk_directory (%s) failed.", dir->path);