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 #1208 from jy2wong/master
[collectd.git]
/
src
/
daemon
/
configfile.c
diff --git
a/src/daemon/configfile.c
b/src/daemon/configfile.c
index
244124d
..
1d81a65
100644
(file)
--- a/
src/daemon/configfile.c
+++ b/
src/daemon/configfile.c
@@
-72,23
+72,24
@@
typedef struct cf_complex_callback_s
typedef struct cf_value_map_s
{
typedef struct cf_value_map_s
{
- char *key;
- int (*func) (
const
oconfig_item_t *);
+ c
onst c
har *key;
+ int (*func) (oconfig_item_t *);
} cf_value_map_t;
typedef struct cf_global_option_s
{
} cf_value_map_t;
typedef struct cf_global_option_s
{
- char *key;
+ c
onst c
har *key;
char *value;
char *value;
- char *def;
+ c
onst c
har *def;
} cf_global_option_t;
/*
* Prototypes of callback functions
*/
} cf_global_option_t;
/*
* Prototypes of callback functions
*/
-static int dispatch_value_typesdb (const oconfig_item_t *ci);
-static int dispatch_value_plugindir (const oconfig_item_t *ci);
-static int dispatch_loadplugin (const oconfig_item_t *ci);
+static int dispatch_value_typesdb (oconfig_item_t *ci);
+static int dispatch_value_plugindir (oconfig_item_t *ci);
+static int dispatch_loadplugin (oconfig_item_t *ci);
+static int dispatch_block_plugin (oconfig_item_t *ci);
/*
* Private variables
/*
* Private variables
@@
-100,7
+101,8
@@
static cf_value_map_t cf_value_map[] =
{
{"TypesDB", dispatch_value_typesdb},
{"PluginDir", dispatch_value_plugindir},
{
{"TypesDB", dispatch_value_typesdb},
{"PluginDir", dispatch_value_plugindir},
- {"LoadPlugin", dispatch_loadplugin}
+ {"LoadPlugin", dispatch_loadplugin},
+ {"Plugin", dispatch_block_plugin}
};
static int cf_value_map_num = STATIC_ARRAY_SIZE (cf_value_map);
};
static int cf_value_map_num = STATIC_ARRAY_SIZE (cf_value_map);
@@
-154,9
+156,12
@@
static int cf_dispatch (const char *type, const char *orig_key,
int ret;
int i;
int ret;
int i;
+ if (orig_key == NULL)
+ return (EINVAL);
+
DEBUG ("type = %s, key = %s, value = %s",
ESCAPE_NULL(type),
DEBUG ("type = %s, key = %s, value = %s",
ESCAPE_NULL(type),
-
ESCAPE_NULL(orig_key)
,
+
orig_key
,
ESCAPE_NULL(orig_value));
if ((cf_cb = cf_search (type)) == NULL)
ESCAPE_NULL(orig_value));
if ((cf_cb = cf_search (type)) == NULL)
@@
-197,8
+202,6
@@
static int cf_dispatch (const char *type, const char *orig_key,
free (key);
free (value);
free (key);
free (value);
- DEBUG ("cf_dispatch: return (%i)", ret);
-
return (ret);
} /* int cf_dispatch */
return (ret);
} /* int cf_dispatch */
@@
-225,7
+228,7
@@
static int dispatch_global_option (const oconfig_item_t *ci)
return (-1);
} /* int dispatch_global_option */
return (-1);
} /* int dispatch_global_option */
-static int dispatch_value_typesdb (
const
oconfig_item_t *ci)
+static int dispatch_value_typesdb (oconfig_item_t *ci)
{
int i = 0;
{
int i = 0;
@@
-251,10
+254,10
@@
static int dispatch_value_typesdb (const oconfig_item_t *ci)
return (0);
} /* int dispatch_value_typesdb */
return (0);
} /* int dispatch_value_typesdb */
-static int dispatch_value_plugindir (
const
oconfig_item_t *ci)
+static int dispatch_value_plugindir (oconfig_item_t *ci)
{
assert (strcasecmp (ci->key, "PluginDir") == 0);
{
assert (strcasecmp (ci->key, "PluginDir") == 0);
-
+
if (ci->values_num != 1)
return (-1);
if (ci->values[0].type != OCONFIG_TYPE_STRING)
if (ci->values_num != 1)
return (-1);
if (ci->values[0].type != OCONFIG_TYPE_STRING)
@@
-264,7
+267,7
@@
static int dispatch_value_plugindir (const oconfig_item_t *ci)
return (0);
}
return (0);
}
-static int dispatch_loadplugin (
const
oconfig_item_t *ci)
+static int dispatch_loadplugin (oconfig_item_t *ci)
{
int i;
const char *name;
{
int i;
const char *name;
@@
-353,7
+356,7
@@
static int dispatch_value_plugin (const char *plugin, oconfig_item_t *ci)
return (cf_dispatch (plugin, ci->key, buffer_ptr));
} /* int dispatch_value_plugin */
return (cf_dispatch (plugin, ci->key, buffer_ptr));
} /* int dispatch_value_plugin */
-static int dispatch_value (
const
oconfig_item_t *ci)
+static int dispatch_value (oconfig_item_t *ci)
{
int ret = -2;
int i;
{
int ret = -2;
int i;
@@
-378,7
+381,7
@@
static int dispatch_value (const oconfig_item_t *ci)
static int dispatch_block_plugin (oconfig_item_t *ci)
{
int i;
static int dispatch_block_plugin (oconfig_item_t *ci)
{
int i;
- char *name;
+ c
onst c
har *name;
cf_complex_callback_t *cb;
cf_complex_callback_t *cb;
@@
-402,9
+405,19
@@
static int dispatch_block_plugin (oconfig_item_t *ci)
if (IS_TRUE (global_option_get ("AutoLoadPlugin")))
{
if (IS_TRUE (global_option_get ("AutoLoadPlugin")))
{
+ plugin_ctx_t ctx;
+ plugin_ctx_t old_ctx;
int status;
int status;
+ /* default to the global interval set before loading this plugin */
+ memset (&ctx, 0, sizeof (ctx));
+ ctx.interval = cf_get_default_interval ();
+
+ old_ctx = plugin_set_ctx (ctx);
status = plugin_load (name, /* flags = */ 0);
status = plugin_load (name, /* flags = */ 0);
+ /* reset to the "global" context */
+ plugin_set_ctx (old_ctx);
+
if (status != 0)
{
ERROR ("Automatically loading plugin \"%s\" failed "
if (status != 0)
{
ERROR ("Automatically loading plugin \"%s\" failed "
@@
-615,8
+628,11
@@
static int cf_include_all (oconfig_item_t *root, int depth)
return (-1);
/* Now replace the i'th child in `root' with `new'. */
return (-1);
/* Now replace the i'th child in `root' with `new'. */
- if (cf_ci_replace_child (root, new, i) < 0)
+ if (cf_ci_replace_child (root, new, i) < 0) {
+ sfree (new->values);
+ sfree (new);
return (-1);
return (-1);
+ }
/* ... and go back to the new i'th child. */
--i;
/* ... and go back to the new i'th child. */
--i;
@@
-701,13
+717,13
@@
static oconfig_item_t *cf_read_dir (const char *dir,
return (NULL);
}
return (NULL);
}
- root =
(oconfig_item_t *) malloc (sizeof (oconfig_item_
t));
+ root =
calloc (1, sizeof (*roo
t));
if (root == NULL)
{
if (root == NULL)
{
- ERROR ("configfile: malloc failed.");
+ ERROR ("configfile: calloc failed.");
+ closedir (dh);
return (NULL);
}
return (NULL);
}
- memset (root, 0, sizeof (oconfig_item_t));
while ((de = readdir (dh)) != NULL)
{
while ((de = readdir (dh)) != NULL)
{
@@
-724,6
+740,7
@@
static oconfig_item_t *cf_read_dir (const char *dir,
ERROR ("configfile: Not including `%s/%s' because its"
" name is too long.",
dir, de->d_name);
ERROR ("configfile: Not including `%s/%s' because its"
" name is too long.",
dir, de->d_name);
+ closedir (dh);
for (i = 0; i < filenames_num; ++i)
free (filenames[i]);
free (filenames);
for (i = 0; i < filenames_num; ++i)
free (filenames[i]);
free (filenames);
@@
-736,6
+753,7
@@
static oconfig_item_t *cf_read_dir (const char *dir,
filenames_num * sizeof (*filenames));
if (tmp == NULL) {
ERROR ("configfile: realloc failed.");
filenames_num * sizeof (*filenames));
if (tmp == NULL) {
ERROR ("configfile: realloc failed.");
+ closedir (dh);
for (i = 0; i < filenames_num - 1; ++i)
free (filenames[i]);
free (filenames);
for (i = 0; i < filenames_num - 1; ++i)
free (filenames[i]);
free (filenames);
@@
-747,6
+765,12
@@
static oconfig_item_t *cf_read_dir (const char *dir,
filenames[filenames_num - 1] = sstrdup (name);
}
filenames[filenames_num - 1] = sstrdup (name);
}
+ if (filenames == NULL)
+ {
+ closedir (dh);
+ return (root);
+ }
+
qsort ((void *) filenames, filenames_num, sizeof (*filenames),
cf_compare_string);
qsort ((void *) filenames, filenames_num, sizeof (*filenames),
cf_compare_string);
@@
-770,11
+794,12
@@
static oconfig_item_t *cf_read_dir (const char *dir,
free (name);
}
free (name);
}
+ closedir (dh);
free(filenames);
return (root);
} /* oconfig_item_t *cf_read_dir */
free(filenames);
return (root);
} /* oconfig_item_t *cf_read_dir */
-/*
+/*
* cf_read_generic
*
* Path is stat'ed and either cf_read_file or cf_read_dir is called
* cf_read_generic
*
* Path is stat'ed and either cf_read_file or cf_read_dir is called
@@
-809,13
+834,12
@@
static oconfig_item_t *cf_read_generic (const char *path,
return (NULL);
}
return (NULL);
}
- root =
(oconfig_item_t *) malloc (sizeof (oconfig_item_
t));
+ root =
calloc (1, sizeof (*roo
t));
if (root == NULL)
{
if (root == NULL)
{
- ERROR ("configfile:
m
alloc failed.");
+ ERROR ("configfile:
c
alloc failed.");
return (NULL);
}
return (NULL);
}
- memset (root, '\0', sizeof (oconfig_item_t));
/* wordexp() might return a sorted list already. That's not
* documented though, so let's make sure we get what we want. */
/* wordexp() might return a sorted list already. That's not
* documented though, so let's make sure we get what we want. */
@@
-900,7
+924,7
@@
static oconfig_item_t *cf_read_generic (const char *path,
} /* oconfig_item_t *cf_read_generic */
#endif /* !HAVE_WORDEXP_H */
} /* oconfig_item_t *cf_read_generic */
#endif /* !HAVE_WORDEXP_H */
-/*
+/*
* Public functions
*/
int global_option_set (const char *option, const char *value)
* Public functions
*/
int global_option_set (const char *option, const char *value)
@@
-943,7
+967,7
@@
const char *global_option_get (const char *option)
if (i >= cf_global_options_num)
return (NULL);
if (i >= cf_global_options_num)
return (NULL);
-
+
return ((cf_global_options[i].value != NULL)
? cf_global_options[i].value
: cf_global_options[i].def);
return ((cf_global_options[i].value != NULL)
? cf_global_options[i].value
: cf_global_options[i].def);
@@
-1041,7
+1065,7
@@
void cf_register (const char *type,
cf_unregister (type);
/* This pointer will be free'd in `cf_unregister' */
cf_unregister (type);
/* This pointer will be free'd in `cf_unregister' */
- if ((cf_cb =
(cf_callback_t *) malloc (sizeof (cf_callback_t
))) == NULL)
+ if ((cf_cb =
malloc (sizeof (*cf_cb
))) == NULL)
return;
cf_cb->type = type;
return;
cf_cb->type = type;
@@
-1058,7
+1082,7
@@
int cf_register_complex (const char *type, int (*callback) (oconfig_item_t *))
{
cf_complex_callback_t *new;
{
cf_complex_callback_t *new;
- new =
(cf_complex_callback_t *) malloc (sizeof (cf_complex_callback_t
));
+ new =
malloc (sizeof (*new
));
if (new == NULL)
return (-1);
if (new == NULL)
return (-1);
@@
-1089,7
+1113,7
@@
int cf_register_complex (const char *type, int (*callback) (oconfig_item_t *))
return (0);
} /* int cf_register_complex */
return (0);
} /* int cf_register_complex */
-int cf_read (char *filename)
+int cf_read (c
onst c
har *filename)
{
oconfig_item_t *conf;
int i;
{
oconfig_item_t *conf;
int i;