summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f59d051)
raw | patch | inline | side by side (parent: f59d051)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Tue, 17 Apr 2007 20:51:56 +0000 (22:51 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Tue, 17 Apr 2007 20:51:56 +0000 (22:51 +0200) |
src/perl.c | patch | blob | history |
diff --git a/src/perl.c b/src/perl.c
index 48da338910cacb4779d5ebf3180bd2d49aee9c65..ebdacb8aa4839255fb2a04f38e1a353bb9a5e5f7 100644 (file)
--- a/src/perl.c
+++ b/src/perl.c
static PerlInterpreter *perl = NULL;
-static char base_name[DATA_MAX_NAME_LEN] = "Collectd::Plugin";
+static char base_name[DATA_MAX_NAME_LEN] = "";
static char *plugin_types[] = { "init", "read", "write", "shutdown" };
static HV *plugins[PLUGIN_TYPES];
* Internal functions.
*/
+static char *get_module_name (char *buf, size_t buf_len, const char *module) {
+ int status = 0;
+ if (base_name[0] == '\0')
+ status = snprintf (buf, buf_len, "%s", module);
+ else
+ status = snprintf (buf, buf_len, "%s::%s", base_name, module);
+ if ((status < 0) || (status >= buf_len))
+ return (NULL);
+ buf[buf_len] = '\0';
+ return (buf);
+} /* char *get_module_name */
+
/*
* Add a new plugin with the given name.
*/
if (p->wait_time > 86400)
p->wait_time = 86400;
- log_warn ("%s::%s->read() failed. Will suspend it for %i seconds.",
- base_name, plugin, p->wait_left);
+ log_warn ("%s->read() failed. Will suspend it for %i seconds.",
+ plugin, p->wait_left);
}
else if (PLUGIN_INIT == type) {
int i = 0;
- log_err ("%s::%s->init() failed. Plugin will be disabled.",
- base_name, plugin, status);
+ log_err ("%s->init() failed. Plugin will be disabled.",
+ plugin, status);
for (i = 0; i < PLUGIN_TYPES; ++i)
pplugin_unregister (i, plugin);
}
else if (PLUGIN_LOG != type) {
- log_warn ("%s::%s->%s() failed with status %i.",
- base_name, plugin, plugin_types[type], status);
+ log_warn ("%s->%s() failed with status %i.",
+ plugin, plugin_types[type], status);
}
va_end (ap);
log_debug ("perl_config: key = \"%s\", value=\"%s\"", key, value);
if (0 == strcasecmp (key, "LoadPlugin")) {
- log_debug ("perl_config: loading perl plugin \"%s\"", value);
+ char module_name[DATA_MAX_NAME_LEN];
+ if (get_module_name (module_name, sizeof (module_name), value)
+ == NULL) {
+ log_err ("Invalid module name %s", value);
+ return (1);
+ } /* if (get_module_name == NULL) */
+
+ log_debug ("perl_config: loading perl plugin \"%s\"", value);
Perl_load_module (perl, PERL_LOADMOD_NOIMPORT,
- Perl_newSVpvf (perl, "%s::%s", base_name, value),
+ newSVpv (module_name, strlen (module_name)),
Nullsv);
}
else if (0 == strcasecmp (key, "BaseName")) {
log_debug ("perl_config: Setting plugin basename to \"%s\"", value);
- strncpy (base_name, value, DATA_MAX_NAME_LEN);
- base_name[DATA_MAX_NAME_LEN - 1] = '\0';
+ strncpy (base_name, value, sizeof (base_name));
+ base_name[sizeof (base_name) - 1] = '\0';
}
else {
return -1;