![]() |
Icinga-core 1.4.0
next gen monitoring
|
00001 /* 00002 mini_epn.c 00003 00004 */ 00005 00006 #include <EXTERN.h> 00007 #include <perl.h> 00008 #include "epn_icinga.h" 00009 00010 #define MAX_INPUT_CHARS 1024 00011 00012 static PerlInterpreter *my_perl = NULL; 00013 00014 int main(int argc, char **argv, char **env) { 00015 00016 /* 00017 #ifdef aTHX 00018 dTHX; 00019 #endif 00020 */ 00021 00022 char *embedding[] = { "", "p1.pl" }; 00023 char *plugin_output ; 00024 char fname[MAX_INPUT_CHARS]; 00025 char *args[] = {"","0", "", "", NULL }; 00026 char command_line[MAX_INPUT_CHARS]; 00027 int exitstatus; 00028 int pclose_result; 00029 00030 if((my_perl=perl_alloc())==NULL){ 00031 printf("%s\n","Error: Could not allocate memory for embedded Perl interpreter!"); 00032 exit(1); 00033 } 00034 perl_construct(my_perl); 00035 exitstatus=perl_parse(my_perl,xs_init,2,embedding,NULL); 00036 if(!exitstatus) { 00037 00038 exitstatus=perl_run(my_perl); 00039 00040 while(printf("Enter file name: ") && fgets(command_line, MAX_INPUT_CHARS-1, stdin)) { 00041 SV *plugin_hndlr_cr; 00042 STRLEN n_a; 00043 int count = 0 ; 00044 00045 dSP; 00046 00047 command_line[strlen(command_line) -1] = '\0'; 00048 00049 strncpy(fname,command_line,strcspn(command_line," ")); 00050 fname[strcspn(command_line," ")] = '\x0'; 00051 args[0] = fname ; 00052 args[3] = command_line + strlen(fname) + 1 ; 00053 00054 args[2] = ""; 00055 00056 /* call our perl interpreter to compile and optionally cache the command */ 00057 00058 ENTER; 00059 SAVETMPS; 00060 PUSHMARK(SP); 00061 00062 XPUSHs(sv_2mortal(newSVpv(args[0],0))); 00063 XPUSHs(sv_2mortal(newSVpv(args[1],0))); 00064 XPUSHs(sv_2mortal(newSVpv(args[2],0))); 00065 XPUSHs(sv_2mortal(newSVpv(args[3],0))); 00066 00067 PUTBACK; 00068 00069 count = call_pv("Embed::Persistent::eval_file", G_SCALAR | G_EVAL); 00070 00071 SPAGAIN; 00072 00073 /* check return status */ 00074 if(SvTRUE(ERRSV)){ 00075 (void) POPs; 00076 00077 pclose_result=-2; 00078 printf("embedded perl ran %s with error %s\n",fname,SvPVX(ERRSV)); 00079 continue; 00080 } else { 00081 plugin_hndlr_cr = newSVsv(POPs); 00082 00083 PUTBACK; 00084 FREETMPS; 00085 LEAVE; 00086 } 00087 00088 ENTER; 00089 SAVETMPS; 00090 PUSHMARK(SP); 00091 00092 XPUSHs(sv_2mortal(newSVpv(args[0],0))); 00093 XPUSHs(sv_2mortal(newSVpv(args[1],0))); 00094 XPUSHs(plugin_hndlr_cr); 00095 XPUSHs(sv_2mortal(newSVpv(args[3],0))); 00096 00097 PUTBACK; 00098 00099 count = perl_call_pv("Embed::Persistent::run_package", G_EVAL | G_ARRAY); 00100 00101 SPAGAIN; 00102 00103 plugin_output = POPpx ; 00104 pclose_result = POPi ; 00105 00106 printf("embedded perl plugin return code and output was: %d & '%s'\n", pclose_result, plugin_output); 00107 00108 PUTBACK; 00109 FREETMPS; 00110 LEAVE; 00111 00112 } 00113 00114 } 00115 00116 00117 PL_perl_destruct_level = 0; 00118 perl_destruct(my_perl); 00119 perl_free(my_perl); 00120 exit(exitstatus); 00121 }