X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fperl.c;h=84dd5372758474cbc6321bdb1ebce5971b681f2e;hb=3f2f61c7d74d9204405a4b0c21390451c98665a7;hp=bd6345baf4d8790effb3f579dbf2f2a4e3a3a92a;hpb=250dc17bfb3c5488b789347f1f570913701d31ca;p=collectd.git diff --git a/src/perl.c b/src/perl.c index bd6345ba..84dd5372 100644 --- a/src/perl.c +++ b/src/perl.c @@ -27,13 +27,19 @@ /* do not automatically get the thread specific perl interpreter */ #define PERL_NO_GET_CONTEXT +#define DONT_POISON_SPRINTF_YET 1 #include "collectd.h" +#undef DONT_POISON_SPRINTF_YET #include "configfile.h" #include #include +#if __GNUC__ +# pragma GCC poison sprintf +#endif + #include /* Some versions of Perl define their own version of DEBUG... :-/ */ @@ -559,7 +565,7 @@ static int pplugin_dispatch_values (pTHX_ char *name, HV *values) list.host[DATA_MAX_NAME_LEN - 1] = '\0'; } else { - strcpy (list.host, hostname_g); + sstrncpy (list.host, hostname_g, sizeof (list.host)); } if (NULL != (tmp = hv_fetch (values, "plugin", 6, 0))) { @@ -1118,7 +1124,7 @@ static c_ithread_t *c_ithread_create (PerlInterpreter *base) aTHX = t->interp; - if (NULL != base) { + if ((NULL != base) && (NULL != PL_endav)) { av_clear (PL_endav); av_undef (PL_endav); PL_endav = Nullav; @@ -1441,7 +1447,7 @@ static int init_pi (int argc, char **argv) log_err ("init_pi: pthread_key_create failed"); /* this must not happen - cowardly giving up if it does */ - exit (1); + return -1; } #ifdef __FreeBSD__ @@ -1476,7 +1482,13 @@ static int init_pi (int argc, char **argv) if (0 != perl_parse (aTHX_ xs_init, argc, argv, NULL)) { log_err ("init_pi: Unable to bootstrap Collectd."); - exit (1); + + perl_destruct (perl_threads->head->interp); + perl_free (perl_threads->head->interp); + sfree (perl_threads); + + pthread_key_delete (perl_thr_key); + return -1; } /* Set $0 to "collectd" because perl_parse() has to set it to "-e". */ @@ -1518,7 +1530,9 @@ static int perl_config_loadplugin (pTHX_ oconfig_item_t *ci) return (1); } - init_pi (perl_argc, perl_argv); + if (0 != init_pi (perl_argc, perl_argv)) + return -1; + assert (NULL != perl_threads); assert (NULL != perl_threads->head); @@ -1634,16 +1648,14 @@ static int perl_config (oconfig_item_t *ci) { int i = 0; - dTHX; - - /* dTHX does not get any valid values in case Perl - * has not been initialized */ - if (NULL == perl_threads) - aTHX = NULL; + dTHXa (NULL); for (i = 0; i < ci->children_num; ++i) { oconfig_item_t *c = ci->children + i; + if (NULL != perl_threads) + aTHX = PERL_GET_CONTEXT; + if (0 == strcasecmp (c->key, "LoadPlugin")) perl_config_loadplugin (aTHX_ c); else if (0 == strcasecmp (c->key, "BaseName"))