Просмотр исходного кода

fix race condition on 'log' command processing

z3APA3A 9 лет назад
Родитель
Сommit
d6f72a51fe
1 измененных файлов с 4 добавлено и 3 удалено
  1. 4 3
      src/conf.c

+ 4 - 3
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;