From: Pavel Rochnyack Date: Fri, 13 May 2016 08:50:31 +0000 (+0600) Subject: perl plugin: lock base thread interpreter in perl_init() too. X-Git-Tag: collectd-5.6.0~291^2~4 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=e58ebe6738bd29699619010484e085c0bb1f0b68;hp=aee1cc1a20b3e7f131835fe5d3ba0f5a51cb6731;p=collectd.git perl plugin: lock base thread interpreter in perl_init() too. Avoid race conditions with c_ithread_create() called from threads of already-initialized plugins. Fix for https://github.com/collectd/collectd/issues/1706. --- diff --git a/src/perl.c b/src/perl.c index 945e2258..0b5debe6 100644 --- a/src/perl.c +++ b/src/perl.c @@ -1,4 +1,4 @@ -/** +/* * collectd - src/perl.c * Copyright (C) 2007-2009 Sebastian Harl * @@ -1911,6 +1911,7 @@ static XS (Collectd_call_by_name) static int perl_init (void) { + int status; dTHX; if (NULL == perl_threads) @@ -1928,7 +1929,19 @@ static int perl_init (void) 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)