Merge branch 'collectd-4.4' into collectd-4.5
[collectd.git] / src / perl.c
index e0f19f6..bb62267 100644 (file)
@@ -1561,7 +1561,9 @@ static int init_pi (int argc, char **argv)
        PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
 
        if (0 != perl_parse (aTHX_ xs_init, argc, argv, NULL)) {
-               log_err ("init_pi: Unable to bootstrap Collectd.");
+               SV *err = get_sv ("@", 1);
+               log_err ("init_pi: Unable to bootstrap Collectd: %s",
+                               SvPV_nolen (err));
 
                perl_destruct (perl_threads->head->interp);
                perl_free (perl_threads->head->interp);
@@ -1768,10 +1770,10 @@ static int perl_config_plugin (pTHX_ oconfig_item_t *ci)
        if (0 < retvals) {
                SV *tmp = POPs;
                if (! SvTRUE (tmp))
-                       ret = -1;
+                       ret = 1;
        }
        else
-               ret = -1;
+               ret = 1;
 
        PUTBACK;
        FREETMPS;
@@ -1781,32 +1783,41 @@ static int perl_config_plugin (pTHX_ oconfig_item_t *ci)
 
 static int perl_config (oconfig_item_t *ci)
 {
+       int status = 0;
        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;
+               int current_status;
+
+               if (NULL != perl_threads)
+                       aTHX = PERL_GET_CONTEXT;
 
                if (0 == strcasecmp (c->key, "LoadPlugin"))
-                       perl_config_loadplugin (aTHX_ c);
+                       current_status = perl_config_loadplugin (aTHX_ c);
                else if (0 == strcasecmp (c->key, "BaseName"))
-                       perl_config_basename (aTHX_ c);
+                       current_status = perl_config_basename (aTHX_ c);
                else if (0 == strcasecmp (c->key, "EnableDebugger"))
-                       perl_config_enabledebugger (aTHX_ c);
+                       current_status = perl_config_enabledebugger (aTHX_ c);
                else if (0 == strcasecmp (c->key, "IncludeDir"))
-                       perl_config_includedir (aTHX_ c);
+                       current_status = perl_config_includedir (aTHX_ c);
                else if (0 == strcasecmp (c->key, "Plugin"))
-                       perl_config_plugin (aTHX_ c);
+                       current_status = perl_config_plugin (aTHX_ c);
                else
                        log_warn ("Ignoring unknown config key \"%s\".", c->key);
+
+               /* fatal error - it's up to perl_config_* to clean up */
+               if (0 > current_status) {
+                       log_err ("Configuration failed with a fatal error - "
+                                       "plugin disabled!");
+                       return current_status;
+               }
+
+               status += current_status;
        }
-       return 0;
+       return status;
 } /* static int perl_config (oconfig_item_t *) */
 
 void module_register (void)