From d6f72a51fe46b55758d63ca6bc09bbc5bf6199fc Mon Sep 17 00:00:00 2001 From: z3APA3A <3APA3A@3proxy.ru> Date: Mon, 4 Apr 2016 13:43:08 +0300 Subject: [PATCH] fix race condition on 'log' command processing --- src/conf.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/conf.c b/src/conf.c index 8e23d32..6730011 100644 --- a/src/conf.c +++ b/src/conf.c @@ -314,22 +314,23 @@ static int h_log(int argc, unsigned char ** argv){ } conf.logtime = time(0); if(conf.logname)myfree(conf.logname); + pthread_mutex_lock(&log_mutex); conf.logname = (unsigned char *)mystrdup((char *)argv[1]); fp = fopen((char *)dologname (tmpbuf, conf.logname, NULL, conf.logtype, conf.logtime), "a"); if(!fp){ - perror("fopen()"); + perror(tmpbuf); + pthread_mutex_unlock(&log_mutex); return 1; } else { - pthread_mutex_lock(&log_mutex); if(conf.stdlog)fclose(conf.stdlog); conf.stdlog = fp; - pthread_mutex_unlock(&log_mutex); #ifdef _WINCE freopen(tmpbuf, "w", stdout); freopen(tmpbuf, "w", stderr); #endif } + pthread_mutex_unlock(&log_mutex); } } return 0;