perl plugin: Mark thread as running to avoid deadlock moved from perl_shutdown()...
[collectd.git] / src / perl.c
index 9f7b869..1dd57a2 100644 (file)
@@ -22,6 +22,7 @@
  *
  * Authors:
  *   Sebastian Harl <sh at tokkee.org>
+ *   Pavel Rochnyak <pavel2000 ngs.ru>
  **/
 
 /*
@@ -1228,6 +1229,10 @@ static void c_ithread_destroy (c_ithread_t *ithread)
        assert (NULL != perl_threads);
 
        PERL_SET_CONTEXT (aTHX);
+       /* Mark as running to avoid deadlock:
+          c_ithread_destroy -> log_debug -> perl_log()
+       */
+       ithread->running = 1;
        log_debug ("Shutting down Perl interpreter %p...", aTHX);
 
 #if COLLECT_DEBUG
@@ -1628,7 +1633,7 @@ static void _plugin_register_generic_userdata (pTHX, int type, const char *desc)
 {
        int ret   = 0;
        user_data_t userdata;
-       char cb_name[DATA_MAX_NAME_LEN];
+       char *pluginname;
 
        dXSARGS;
 
@@ -1649,11 +1654,13 @@ static void _plugin_register_generic_userdata (pTHX, int type, const char *desc)
                XSRETURN_EMPTY;
        }
 
+       /* Use pluginname as-is to allow flush a single perl plugin */
+       pluginname = SvPV_nolen (ST (0));
+
        log_debug ("Collectd::plugin_register_%s: "
                        "plugin = \"%s\", sub = \"%s\"",
-                       desc, SvPV_nolen (ST (0)), SvPV_nolen (ST (1)));
+                       desc, pluginname, SvPV_nolen (ST (1)));
 
-       ssnprintf (cb_name, sizeof (cb_name), "perl/%s", SvPV_nolen (ST (0)));
        memset(&userdata, 0, sizeof(userdata));
        userdata.data = strdup(SvPV_nolen (ST (1)));
        userdata.free_func = free;
@@ -1661,22 +1668,22 @@ static void _plugin_register_generic_userdata (pTHX, int type, const char *desc)
        if (PLUGIN_READ == type) {
                ret = plugin_register_complex_read(
                        "perl",                /* group */
-                       cb_name,
+                       pluginname,
                        perl_read,
                        plugin_get_interval(), /* Default interval */
                        &userdata);
        }
        else if (PLUGIN_WRITE == type) {
-               ret = plugin_register_write(cb_name, perl_write, &userdata);
+               ret = plugin_register_write(pluginname, perl_write, &userdata);
        }
        else if (PLUGIN_LOG == type) {
-               ret = plugin_register_log(cb_name, perl_log, &userdata);
+               ret = plugin_register_log(pluginname, perl_log, &userdata);
        }
        else if (PLUGIN_NOTIF == type) {
-               ret = plugin_register_notification(cb_name, perl_notify, &userdata);
+               ret = plugin_register_notification(pluginname, perl_notify, &userdata);
        }
        else if (PLUGIN_FLUSH == type) {
-               ret = plugin_register_flush(cb_name, perl_flush, &userdata);
+               ret = plugin_register_flush(pluginname, perl_flush, &userdata);
        }
        else {
                ret = -1;
@@ -2368,10 +2375,6 @@ static int perl_shutdown (void)
                        pthread_kill (thr->pthread, SIGTERM);
                        ERROR ("perl shutdown: Thread hangs inside Perl. Thread killed.");
                }
-               /* Mark as running to avoid deadlock:
-                  c_ithread_destroy -> log_debug -> perl_log()
-               */
-               thr->running = 1; 
                c_ithread_destroy (thr);
        }