perl plugin: Don't abort if initializing the interpreter failed.
[collectd.git] / src / perl.c
index bd6345b..9bd3b4d 100644 (file)
@@ -1441,7 +1441,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 +1476,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 +1524,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);