[collectd] [PATCH] perl plugin: Improved "IncludeDir" configuration option.

Sebastian Harl sh at tokkee.org
Wed Oct 17 01:13:35 CEST 2007


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 <sh at tokkee.org>
---
 src/perl.c |   28 ++++++++++++++++++----------
 1 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/perl.c b/src/perl.c
index 8c21e45..c0beabf 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 *) */
 
-- 
1.5.3.4.206.g58ba4

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20071017/36f7e0b0/attachment.pgp 


More information about the collectd mailing list