[Nagios-devel] [PATCH] Always initialize embedded perl if compiled

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Guest

[Nagios-devel] [PATCH] Always initialize embedded perl if compiled

Post by Guest »

From: Andreas Ericsson

libc defines readdir() et al as weak symbols, free to be
overridden by other libraries. epn brings in a library that
redefines it, but it will segfault if not initialized.

This patch forces initialization of the embedded perl
interpreter even if it's turned off in the configuration,
working around the problem at the expense of a slightly
larger memory footprint.

Signed-off-by: Andreas Ericsson
---
base/nagios.c | 14 ++------------
base/utils.c | 9 ++++-----
2 files changed, 6 insertions(+), 17 deletions(-)

diff --git a/base/nagios.c b/base/nagios.c
index 663177b..3dbda04 100644
--- a/base/nagios.c
+++ b/base/nagios.c
@@ -268,11 +268,7 @@ unsigned long max_debug_file_size=DEFAULT_MAX_DEBUG_FILE_SIZE;


/* Following main() declaration required by older versions of Perl ut 5.00503 */
-#ifdef EMBEDDEDPERL
int main(int argc, char **argv, char **env){
-#else
-int main(int argc, char **argv){
-#endif
int result;
int error=FALSE;
char *buffer=NULL;
@@ -701,14 +697,8 @@ int main(int argc, char **argv){

/* initialize embedded Perl interpreter */
if(embedded_perl_initialized==FALSE){
- if(enable_embedded_perl==TRUE){
-#ifdef EMBEDDEDPERL
- init_embedded_perl(env);
-#else
- init_embedded_perl(NULL);
-#endif
- embedded_perl_initialized=TRUE;
- }
+ init_embedded_perl(env);
+ embedded_perl_initialized=TRUE;
}

/* handle signals (interrupts) */
diff --git a/base/utils.c b/base/utils.c
index ebf3640..c64a2c4 100644
--- a/base/utils.c
+++ b/base/utils.c
@@ -3560,11 +3560,12 @@ int init_embedded_perl(char **env){
char *temp_buffer=NULL;
int argc=2;
struct stat stat_buf;
+ int init_ok = TRUE;

/* make sure the P1 file exists... */
if(p1_file==NULL || stat(p1_file,&stat_buf)!=0){

- use_embedded_perl=FALSE;
+ init_ok=FALSE;

logit(NSLOG_RUNTIME_ERROR,TRUE,"Error: p1.pl file required for embedded Perl interpreter is missing!\n");
}
@@ -3573,18 +3574,16 @@ int init_embedded_perl(char **env){

embedding[1]=p1_file;

- use_embedded_perl=TRUE;
-
PERL_SYS_INIT3(&argc,&embedding,&env);

if((my_perl=perl_alloc())==NULL){
- use_embedded_perl=FALSE;
+ init_ok=FALSE;
logit(NSLOG_RUNTIME_ERROR,TRUE,"Error: Could not allocate memory for embedded Perl interpreter!\n");
}
}

/* a fatal error occurred... */
- if(use_embedded_perl==FALSE){
+ if(init_ok==FALSE){

logit(NSLOG_PROCESS_INFO | NSLOG_RUNTIME_ERROR,TRUE,"Bailing out due to errors encountered while initializing the embedded Perl interpreter. (PID=%d)\n",(int)getpid());

--
1.5.4.1.100.gec3a






This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
Locked