summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: aee1cc1)
raw | patch | inline | side by side (parent: aee1cc1)
author | Pavel Rochnyack <pavel2000@ngs.ru> | |
Fri, 13 May 2016 08:50:31 +0000 (14:50 +0600) | ||
committer | Pavel Rochnyack <pavel2000@ngs.ru> | |
Sun, 29 May 2016 06:22:55 +0000 (12:22 +0600) |
Avoid race conditions with c_ithread_create() called from threads of already-initialized plugins.
Fix for https://github.com/collectd/collectd/issues/1706.
Fix for https://github.com/collectd/collectd/issues/1706.
src/perl.c | patch | blob | history |
diff --git a/src/perl.c b/src/perl.c
index 945e22586c806e2b3000f18c78e201cbbf74fff4..0b5debe67730ce99e218bde5a41461b51e16ec3d 100644 (file)
--- a/src/perl.c
+++ b/src/perl.c
-/**
+/*
* collectd - src/perl.c
* Copyright (C) 2007-2009 Sebastian Harl
*
static int perl_init (void)
{
+ int status;
dTHX;
if (NULL == perl_threads)
log_debug ("perl_init: c_ithread: interp = %p (active threads: %i)",
aTHX, perl_threads->number_of_threads);
- return pplugin_call_all (aTHX_ PLUGIN_INIT);
+
+ /* Lock the base thread to avoid race conditions with c_ithread_create().
+ * See https://github.com/collectd/collectd/issues/9 and
+ * https://github.com/collectd/collectd/issues/1706 for details. */
+
+ assert (aTHX == perl_threads->head->interp);
+ pthread_mutex_lock (&perl_threads->mutex);
+
+ status = pplugin_call_all (aTHX_ PLUGIN_INIT);
+
+ pthread_mutex_unlock (&perl_threads->mutex);
+
+ return status;
} /* static int perl_init (void) */
static int perl_read (void)