fix race condition on 'log' command processing

This commit is contained in:
z3APA3A 2016-04-04 13:43:08 +03:00
parent 6cac541e33
commit d6f72a51fe

View File

@ -314,22 +314,23 @@ static int h_log(int argc, unsigned char ** argv){
} }
conf.logtime = time(0); conf.logtime = time(0);
if(conf.logname)myfree(conf.logname); if(conf.logname)myfree(conf.logname);
pthread_mutex_lock(&log_mutex);
conf.logname = (unsigned char *)mystrdup((char *)argv[1]); conf.logname = (unsigned char *)mystrdup((char *)argv[1]);
fp = fopen((char *)dologname (tmpbuf, conf.logname, NULL, conf.logtype, conf.logtime), "a"); fp = fopen((char *)dologname (tmpbuf, conf.logname, NULL, conf.logtype, conf.logtime), "a");
if(!fp){ if(!fp){
perror("fopen()"); perror(tmpbuf);
pthread_mutex_unlock(&log_mutex);
return 1; return 1;
} }
else { else {
pthread_mutex_lock(&log_mutex);
if(conf.stdlog)fclose(conf.stdlog); if(conf.stdlog)fclose(conf.stdlog);
conf.stdlog = fp; conf.stdlog = fp;
pthread_mutex_unlock(&log_mutex);
#ifdef _WINCE #ifdef _WINCE
freopen(tmpbuf, "w", stdout); freopen(tmpbuf, "w", stdout);
freopen(tmpbuf, "w", stderr); freopen(tmpbuf, "w", stderr);
#endif #endif
} }
pthread_mutex_unlock(&log_mutex);
} }
} }
return 0; return 0;