From: Pavel Rochnyack Date: Wed, 12 Jul 2017 14:06:22 +0000 (+0700) Subject: snmp_agent: Avoid race conditions between thread start and locks initialization. X-Git-Tag: collectd-5.8.0~120^2~4 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=9bdf6cbef6eaf867b3a614fdf544cf3b38712ef7;p=collectd.git snmp_agent: Avoid race conditions between thread start and locks initialization. Lock initialization should be done before starting pthread which uses them. --- diff --git a/src/snmp_agent.c b/src/snmp_agent.c index 0908b4eb..1ea5cc97 100644 --- a/src/snmp_agent.c +++ b/src/snmp_agent.c @@ -1406,13 +1406,6 @@ static int snmp_agent_init(void) { if (ret != 0) return ret; - /* create a second thread to listen for requests from AgentX*/ - ret = pthread_create(&g_agent->thread, NULL, &snmp_agent_thread_run, NULL); - if (ret != 0) { - ERROR(PLUGIN_NAME ": Failed to create a separate thread, err %u", ret); - return ret; - } - ret = pthread_mutex_init(&g_agent->lock, NULL); if (ret != 0) { ERROR(PLUGIN_NAME ": Failed to initialize mutex, err %u", ret); @@ -1425,6 +1418,13 @@ static int snmp_agent_init(void) { return ret; } + /* create a second thread to listen for requests from AgentX*/ + ret = pthread_create(&g_agent->thread, NULL, &snmp_agent_thread_run, NULL); + if (ret != 0) { + ERROR(PLUGIN_NAME ": Failed to create a separate thread, err %u", ret); + return ret; + } + return 0; }