Code

perl plugin: Disable plugin after fatal configuration errors.
authorSebastian Harl <sh@tokkee.org>
Tue, 16 Sep 2008 13:40:14 +0000 (15:40 +0200)
committerFlorian Forster <octo@huhu.verplant.org>
Wed, 1 Oct 2008 07:48:56 +0000 (09:48 +0200)
Currently, the only such case is the failure to bootstrap the Perl interpreter
and Collectd module. This fixes a segfault that happened when trying to
configure Perl plugins in that case.

Signed-off-by: Sebastian Harl <sh@tokkee.org>
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
src/perl.c

index e6f7de0e0de71ed75647c3f26548e98e3243ff85..6d95082457b2654e65a8a3b7c5e46103310ee8e2 100644 (file)
@@ -1768,10 +1768,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,30 +1781,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;
 
        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)