From: Sebastian Harl Date: Tue, 16 Oct 2007 23:13:35 +0000 (+0200) Subject: perl plugin: Improved "IncludeDir" configuration option. X-Git-Tag: collectd-4.2.0~17 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=caaf25432e9db92f9b35e18ae45b41d19910fcc7;p=collectd.git perl plugin: Improved "IncludeDir" configuration option. The "Do not initialize the Perl interpreter until loading a module." commit removed support for adding include directories after the Perl interpreter has been initialized. This patch re-enables it. Signed-off-by: Sebastian Harl Signed-off-by: Florian Forster --- diff --git a/src/perl.c b/src/perl.c index 8c21e45c..c0beabfe 100644 --- a/src/perl.c +++ b/src/perl.c @@ -992,19 +992,27 @@ static int perl_config_includedir (oconfig_item_t *ci) value = ci->values[0].value.string; - perl_argv = (char **)realloc (perl_argv, - (++perl_argc + 1) * sizeof (char *)); + if (NULL == perl) { + perl_argv = (char **)realloc (perl_argv, + (++perl_argc + 1) * sizeof (char *)); - if (NULL == perl_argv) { - log_err ("perl_config: Not enough memory."); - exit (3); - } + if (NULL == perl_argv) { + log_err ("perl_config: Not enough memory."); + exit (3); + } - perl_argv[perl_argc - 1] = (char *)smalloc (strlen (value) + 3); - sstrncpy(perl_argv[perl_argc - 1], "-I", 3); - sstrncpy(perl_argv[perl_argc - 1] + 2, value, strlen (value) + 1); + perl_argv[perl_argc - 1] = (char *)smalloc (strlen (value) + 3); + sstrncpy(perl_argv[perl_argc - 1], "-I", 3); + sstrncpy(perl_argv[perl_argc - 1] + 2, value, strlen (value) + 1); - perl_argv[perl_argc] = NULL; + perl_argv[perl_argc] = NULL; + } + else { + /* prepend the directory to @INC */ + Perl_av_unshift (perl, GvAVn (PL_incgv), 1); + Perl_av_store (perl, GvAVn (PL_incgv), + 0, Perl_newSVpv (perl, value, strlen (value))); + } return 0; } /* static int perl_config_includedir (oconfig_item_it *) */