From 9bdf6cbef6eaf867b3a614fdf544cf3b38712ef7 Mon Sep 17 00:00:00 2001 From: Pavel Rochnyack Date: Wed, 12 Jul 2017 21:06:22 +0700 Subject: [PATCH] snmp_agent: Avoid race conditions between thread start and locks initialization. Lock initialization should be done before starting pthread which uses them. --- src/snmp_agent.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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; } -- 2.11.0