mirror of
				https://github.com/3proxy/3proxy.git
				synced 2025-11-04 07:42:39 +08:00 
			
		
		
		
	Resolve races on log buffer without mutex
This commit is contained in:
		
							parent
							
								
									1d162abec3
								
							
						
					
					
						commit
						d3f9d80b65
					
				@ -192,6 +192,7 @@ void doschedule(void){
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void dumpcounters(struct trafcount *tlin, int counterd){
 | 
					void dumpcounters(struct trafcount *tlin, int counterd){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 unsigned char tmpbuf[8192];
 | 
				
			||||||
 struct trafcount *tl;
 | 
					 struct trafcount *tl;
 | 
				
			||||||
 if(counterd >= 0 && tlin) {
 | 
					 if(counterd >= 0 && tlin) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -234,6 +235,7 @@ void dumpcounters(struct trafcount *tlin, int counterd){
 | 
				
			|||||||
void cyclestep(void){
 | 
					void cyclestep(void){
 | 
				
			||||||
 struct tm *tm;
 | 
					 struct tm *tm;
 | 
				
			||||||
 time_t minutecounter;
 | 
					 time_t minutecounter;
 | 
				
			||||||
 | 
					 unsigned char tmpbuf[8192];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 minutecounter = time(0);
 | 
					 minutecounter = time(0);
 | 
				
			||||||
 for(;;){
 | 
					 for(;;){
 | 
				
			||||||
@ -362,6 +364,7 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int
 | 
				
			|||||||
#ifdef _WIN32
 | 
					#ifdef _WIN32
 | 
				
			||||||
  unsigned char * arg;
 | 
					  unsigned char * arg;
 | 
				
			||||||
  WSADATA wd;
 | 
					  WSADATA wd;
 | 
				
			||||||
 | 
					  unsigned char tmpbuf[8192];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  WSAStartup(MAKEWORD( 1, 1 ), &wd);
 | 
					  WSAStartup(MAKEWORD( 1, 1 ), &wd);
 | 
				
			||||||
  osv.dwOSVersionInfoSize = sizeof(osv);
 | 
					  osv.dwOSVersionInfoSize = sizeof(osv);
 | 
				
			||||||
 | 
				
			|||||||
@ -285,6 +285,7 @@ static int h_external(int argc, unsigned char ** argv){
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int h_log(int argc, unsigned char ** argv){ 
 | 
					static int h_log(int argc, unsigned char ** argv){ 
 | 
				
			||||||
 | 
						unsigned char tmpbuf[8192];
 | 
				
			||||||
	conf.logfunc = logstdout;
 | 
						conf.logfunc = logstdout;
 | 
				
			||||||
	if(conf.logtarget){
 | 
						if(conf.logtarget){
 | 
				
			||||||
		myfree(conf.logtarget);
 | 
							myfree(conf.logtarget);
 | 
				
			||||||
@ -314,12 +315,10 @@ 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(tmpbuf);
 | 
									perror(tmpbuf);
 | 
				
			||||||
				pthread_mutex_unlock(&log_mutex);
 | 
					 | 
				
			||||||
				return 1;
 | 
									return 1;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else {
 | 
								else {
 | 
				
			||||||
@ -330,7 +329,6 @@ static int h_log(int argc, unsigned char ** argv){
 | 
				
			|||||||
				freopen(tmpbuf, "w", stderr);
 | 
									freopen(tmpbuf, "w", stderr);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			pthread_mutex_unlock(&log_mutex);
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user