mirror of
https://github.com/3proxy/3proxy.git
synced 2025-02-23 18:45:40 +08:00
Do not start log thread before logging is actually required to prevent daemon problem
This commit is contained in:
parent
9e51fe7308
commit
b3a843aacb
23
src/log.c
23
src/log.c
@ -26,7 +26,7 @@ typedef enum {
|
||||
FREEPARAM
|
||||
} EVENTTYPE;
|
||||
|
||||
|
||||
static int loginit = 0;
|
||||
|
||||
struct clientparam logparam;
|
||||
struct srvparam logsrv;
|
||||
@ -51,6 +51,8 @@ static void delayregisterlog (struct LOGGER * log);
|
||||
static void delaydolog(struct logevent *evt);
|
||||
static void delayfreeparam(struct clientparam *param);
|
||||
|
||||
static void initlog2(void);
|
||||
|
||||
void logpush(struct logevent *evt);
|
||||
|
||||
#ifdef WITHMAIN
|
||||
@ -163,6 +165,10 @@ struct LOGGER * registerlog(const char * logstring, int logtype){
|
||||
|
||||
if(!logstring || !strcmp(logstring, "NUL") || !strcmp(logstring, "/dev/null")) return NULL;
|
||||
pthread_mutex_lock(&log_mutex);
|
||||
if(!loginit){
|
||||
initlog2();
|
||||
loginit = 1;
|
||||
}
|
||||
for(log = loggers; log; log=log->next){
|
||||
if(!strcmp(logstring, log->selector)){
|
||||
if(logtype >= 0) log->rotate = logtype;
|
||||
@ -297,14 +303,10 @@ void logpush(struct logevent *evt){
|
||||
#endif
|
||||
}
|
||||
|
||||
void initlog(void){
|
||||
static void initlog2(void){
|
||||
pthread_t thread;
|
||||
|
||||
srvinit(&logsrv, &logparam);
|
||||
pthread_mutex_init(&log_mutex, NULL);
|
||||
errld.fp = stdout;
|
||||
#ifdef _WIN32
|
||||
{
|
||||
HANDLE h;
|
||||
if(!(log_sem = CreateSemaphore(NULL, 0, MAX_SEM_COUNT, NULL))) exit(11);
|
||||
#ifndef _WINCE
|
||||
@ -318,9 +320,7 @@ void initlog(void){
|
||||
else {
|
||||
exit(10);
|
||||
}
|
||||
}
|
||||
#else
|
||||
{
|
||||
pthread_attr_t pa;
|
||||
pthread_attr_init(&pa);
|
||||
|
||||
@ -329,10 +329,15 @@ void initlog(void){
|
||||
|
||||
if(sem_init(&log_sem, 0, 0)) exit(11);
|
||||
if(pthread_create(&thread, &pa, logthreadfunc, NULL)) exit(10);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void initlog(void){
|
||||
srvinit(&logsrv, &logparam);
|
||||
pthread_mutex_init(&log_mutex, NULL);
|
||||
errld.fp = stdout;
|
||||
}
|
||||
|
||||
static void delaydolog(struct logevent *evt){
|
||||
|
||||
if(!evt->log->logfunc || !evt->log->logfunc->log) return;
|
||||
|
Loading…
Reference in New Issue
Block a user