diff --git a/src/3proxy.c b/src/3proxy.c index 5c89b8b..c5fac4d 100644 --- a/src/3proxy.c +++ b/src/3proxy.c @@ -271,16 +271,8 @@ void cyclestep(void){ } if(conf.logname) { if(timechanged(conf.logtime, conf.time, conf.logtype)) { - FILE *fp; - fp = fopen((char *)dologname (tmpbuf, conf.logname, NULL, conf.logtype, conf.time), "a"); - if (fp) { - pthread_mutex_lock(&log_mutex); - fclose(conf.stdlog); - conf.stdlog = fp; - pthread_mutex_unlock(&log_mutex); - } - fseek(stdout, 0L, SEEK_END); - usleep(SLEEPTIME); + if(conf.stdlog) conf.stdlog = freopen((char *)dologname (tmpbuf, conf.logname, NULL, conf.logtype, conf.time), "a", conf.stdlog); + else conf.stdlog = fopen((char *)dologname (tmpbuf, conf.logname, NULL, conf.logtype, conf.time), "a"); conf.logtime = conf.time; if(conf.logtype != NONE && conf.rotate) { int t; diff --git a/src/common.c b/src/common.c index dd33020..7b0baeb 100644 --- a/src/common.c +++ b/src/common.c @@ -614,8 +614,7 @@ int dobuf(struct clientparam * param, unsigned char * buf, const unsigned char * time(&t); if(!param) return 0; if(param->trafcountfunc)(*param->trafcountfunc)(param); - format = (char *)param->srv->logformat; - if(!format) format = "G%y%m%d%H%M%S.%. %p %E %U %C:%c %R:%r %O %I %h %T"; + format = param->srv->logformat?(char *)param->srv->logformat : DEFLOGFORMAT; tm = (*format == 'G' || *format == 'g')? gmtime(&t) : localtime(&t); i = dobuf2(param, buf, s, doublec, tm, format + 1); diff --git a/src/conf.c b/src/conf.c index 7a392a2..a7001cf 100644 --- a/src/conf.c +++ b/src/conf.c @@ -301,7 +301,6 @@ static int h_log(int argc, unsigned char ** argv){ havelog = 1; - conf.logfunc = logstdout; if(argc > 1 && conf.logtarget && *argv[1]!= '&' && *argv[1]!= '@' && !strcmp((char *)conf.logtarget, (char *)argv[1])) { return 0; } @@ -336,28 +335,23 @@ static int h_log(int argc, unsigned char ** argv){ } #endif else { - FILE *fp; if(argc > 2) { conf.logtype = getrotate(*argv[2]); } conf.logtime = time(0); if(conf.logname)myfree(conf.logname); conf.logname = (unsigned char *)mystrdup((char *)argv[1]); - fp = fopen((char *)dologname (tmpbuf, conf.logname, NULL, conf.logtype, conf.logtime), "a"); - if(!fp){ + if(conf.stdlog) conf.stdlog = freopen((char *)dologname (tmpbuf, conf.logname, NULL, conf.logtype, conf.logtime), "a", conf.stdlog); + else conf.stdlog = fopen((char *)dologname (tmpbuf, conf.logname, NULL, conf.logtype, conf.logtime), "a"); + if(!conf.stdlog){ perror((char *)tmpbuf); return 1; } - else { - if(conf.stdlog)fclose(conf.stdlog); - conf.stdlog = fp; -#ifdef _WINCE - freopen(tmpbuf, "w", stdout); - freopen(tmpbuf, "w", stderr); -#endif - } + conf.logfunc = logstdout; + } } + else conf.logfunc = logstdout; return 0; } @@ -464,8 +458,9 @@ static int h_rotate(int argc, unsigned char **argv){ } static int h_logformat(int argc, unsigned char **argv){ - if(conf.logformat) myfree(conf.logformat); + unsigned char * old = conf.logformat; conf.logformat = (unsigned char *)mystrdup((char *)argv[1]); + if(old) myfree(old); return 0; } @@ -1807,6 +1802,7 @@ void freeconf(struct extparam *confp){ acl = confp->acl; confp->acl = NULL; confp->logtime = confp->time = 0; + confp->logfunc = lognone; usleep(SLEEPTIME); diff --git a/src/proxy.h b/src/proxy.h index fef6348..8dba399 100644 --- a/src/proxy.h +++ b/src/proxy.h @@ -136,6 +136,8 @@ void daemonize(void); #define MAXRADIUS 5 +#define DEFLOGFORMAT "G%y%m%d%H%M%S.%. %p %E %U %C:%c %R:%r %O %I %h %T" + extern RESOLVFUNC resolvfunc; extern int wday;