mirror of
https://github.com/3proxy/3proxy.git
synced 2025-02-23 18:45:40 +08:00
Unify logging (make it always blocking in exchange for memory)
This commit is contained in:
parent
0487084161
commit
7df2461a26
12
src/3proxy.c
12
src/3proxy.c
@ -19,7 +19,6 @@
|
||||
#endif
|
||||
|
||||
FILE * confopen();
|
||||
extern unsigned char tmpbuf[1024];
|
||||
extern unsigned char *strings[];
|
||||
extern FILE *writable;
|
||||
extern struct counter_header cheader;
|
||||
@ -65,9 +64,9 @@ void __stdcall CommandHandler( DWORD dwCommand )
|
||||
Sleep(2000);
|
||||
SetStatus( SERVICE_STOPPED, 0, 0 );
|
||||
#ifndef NOODBC
|
||||
pthread_mutex_lock(&odbc_mutex);
|
||||
pthread_mutex_lock(&log_mutex);
|
||||
close_sql();
|
||||
pthread_mutex_unlock(&odbc_mutex);
|
||||
pthread_mutex_unlock(&log_mutex);
|
||||
#endif
|
||||
break;
|
||||
case SERVICE_CONTROL_PAUSE:
|
||||
@ -120,9 +119,9 @@ void mysigterm (int sig){
|
||||
usleep(999*SLEEPTIME);
|
||||
usleep(999*SLEEPTIME);
|
||||
#ifndef NOODBC
|
||||
pthread_mutex_lock(&odbc_mutex);
|
||||
pthread_mutex_lock(&log_mutex);
|
||||
close_sql();
|
||||
pthread_mutex_unlock(&odbc_mutex);
|
||||
pthread_mutex_unlock(&log_mutex);
|
||||
#endif
|
||||
conf.timetoexit = 1;
|
||||
}
|
||||
@ -519,9 +518,6 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int
|
||||
pthread_mutex_init(&hash_mutex, NULL);
|
||||
pthread_mutex_init(&tc_mutex, NULL);
|
||||
pthread_mutex_init(&pwl_mutex, NULL);
|
||||
#ifndef NOODBC
|
||||
pthread_mutex_init(&odbc_mutex, NULL);
|
||||
#endif
|
||||
|
||||
freeconf(&conf);
|
||||
res = readconfig(fp);
|
||||
|
21
src/auth.c
21
src/auth.c
@ -1296,46 +1296,45 @@ void sqlerr (char *buf){
|
||||
fprintf(conf.stdlog, "%s\n", buf);
|
||||
fflush(conf.stdlog);
|
||||
}
|
||||
pthread_mutex_unlock(&odbc_mutex);
|
||||
pthread_mutex_unlock(&log_mutex);
|
||||
}
|
||||
|
||||
void logsql(struct clientparam * param, const unsigned char *s) {
|
||||
unsigned char buf[4096];
|
||||
SQLRETURN ret;
|
||||
int len;
|
||||
|
||||
len = dobuf(param, buf, s, "\'");
|
||||
|
||||
if(param->nolog) return;
|
||||
pthread_mutex_lock(&odbc_mutex);
|
||||
pthread_mutex_lock(&log_mutex);
|
||||
len = dobuf(param, tmpbuf, s, "\'");
|
||||
|
||||
if(attempt > 5){
|
||||
time_t t;
|
||||
|
||||
t = time(0);
|
||||
if (t - attempt_time < 180){
|
||||
sqlerr(buf);
|
||||
sqlerr(tmpbuf);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(!hstmt){
|
||||
if(!init_sql(sqlstring)) {
|
||||
sqlerr(buf);
|
||||
sqlerr(tmpbuf);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(hstmt){
|
||||
ret = SQLExecDirect(hstmt, (SQLCHAR *)buf, (SQLINTEGER)len);
|
||||
ret = SQLExecDirect(hstmt, (SQLCHAR *)tmpbuf, (SQLINTEGER)len);
|
||||
if(ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO){
|
||||
close_sql();
|
||||
if(!init_sql(sqlstring)){
|
||||
sqlerr(buf);
|
||||
sqlerr(tmpbuf);
|
||||
return;
|
||||
}
|
||||
if(hstmt) {
|
||||
ret = SQLExecDirect(hstmt, (SQLCHAR *)buf, (SQLINTEGER)len);
|
||||
ret = SQLExecDirect(hstmt, (SQLCHAR *)tmpbuf, (SQLINTEGER)len);
|
||||
if(ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO){
|
||||
sqlerr(buf);
|
||||
sqlerr(tmpbuf);
|
||||
return;
|
||||
}
|
||||
attempt = 0;
|
||||
@ -1343,7 +1342,7 @@ void logsql(struct clientparam * param, const unsigned char *s) {
|
||||
}
|
||||
attempt = 0;
|
||||
}
|
||||
pthread_mutex_unlock(&odbc_mutex);
|
||||
pthread_mutex_unlock(&log_mutex);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
17
src/common.c
17
src/common.c
@ -603,9 +603,9 @@ void lognone(struct clientparam * param, const unsigned char *s) {
|
||||
}
|
||||
pthread_mutex_t log_mutex;
|
||||
int logmutexinit = 0;
|
||||
unsigned char tmpbuf[4096];
|
||||
|
||||
void logstdout(struct clientparam * param, const unsigned char *s) {
|
||||
unsigned char buf[4096];
|
||||
FILE *log;
|
||||
|
||||
if(!logmutexinit){
|
||||
@ -614,8 +614,8 @@ void logstdout(struct clientparam * param, const unsigned char *s) {
|
||||
}
|
||||
pthread_mutex_lock(&log_mutex);
|
||||
log = param->srv->stdlog?param->srv->stdlog:conf.stdlog?conf.stdlog:stdout;
|
||||
dobuf(param, buf, s, NULL);
|
||||
if(!param->nolog)if(fprintf(log, "%s\n", buf) < 0) {
|
||||
dobuf(param, tmpbuf, s, NULL);
|
||||
if(!param->nolog)if(fprintf(log, "%s\n", tmpbuf) < 0) {
|
||||
perror("printf()");
|
||||
};
|
||||
if(log != conf.stdlog)fflush(log);
|
||||
@ -623,10 +623,15 @@ void logstdout(struct clientparam * param, const unsigned char *s) {
|
||||
}
|
||||
#ifndef _WIN32
|
||||
void logsyslog(struct clientparam * param, const unsigned char *s) {
|
||||
unsigned char buf[4096];
|
||||
|
||||
dobuf(param, buf, s, NULL);
|
||||
if(!param->nolog)syslog(LOG_INFO, "%s", buf);
|
||||
if(!logmutexinit){
|
||||
pthread_mutex_init(&log_mutex, NULL);
|
||||
logmutexinit = 1;
|
||||
}
|
||||
pthread_mutex_lock(&log_mutex);
|
||||
dobuf(param, tmpbuf, s, NULL)
|
||||
if(!param->nolog)syslog(LOG_INFO, "%s", tmpbuf);
|
||||
pthread_mutex_unlock(&log_mutex);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -16,14 +16,9 @@ pthread_mutex_t pwl_mutex;
|
||||
pthread_mutex_t hash_mutex;
|
||||
pthread_mutex_t config_mutex;
|
||||
|
||||
#ifndef NOODBC
|
||||
pthread_mutex_t odbc_mutex;
|
||||
#endif
|
||||
|
||||
int haveerror = 0;
|
||||
int linenum = 0;
|
||||
|
||||
unsigned char tmpbuf[1024];
|
||||
FILE *writable;
|
||||
struct counter_header cheader = {"3CF", (time_t)0};
|
||||
struct counter_record crecord;
|
||||
@ -302,10 +297,10 @@ static int h_log(int argc, unsigned char ** argv){
|
||||
}
|
||||
#ifndef NOODBC
|
||||
else if(*argv[1]=='&'){
|
||||
pthread_mutex_lock(&odbc_mutex);
|
||||
pthread_mutex_lock(&log_mutex);
|
||||
close_sql();
|
||||
init_sql((char *)argv[1]+1);
|
||||
pthread_mutex_unlock(&odbc_mutex);
|
||||
pthread_mutex_unlock(&log_mutex);
|
||||
conf.logfunc = logsql;
|
||||
}
|
||||
#endif
|
||||
|
@ -309,7 +309,7 @@ struct datatype;
|
||||
struct dictionary;
|
||||
struct node;
|
||||
struct property;
|
||||
|
||||
extern unsigned char tmpbuf[4096];
|
||||
extern pthread_mutex_t config_mutex;
|
||||
extern pthread_mutex_t bandlim_mutex;
|
||||
extern pthread_mutex_t hash_mutex;
|
||||
@ -317,9 +317,6 @@ extern pthread_mutex_t tc_mutex;
|
||||
extern pthread_mutex_t pwl_mutex;
|
||||
extern pthread_mutex_t log_mutex;
|
||||
extern int logmutexinit;
|
||||
#ifndef NOODBC
|
||||
extern pthread_mutex_t odbc_mutex;
|
||||
#endif
|
||||
|
||||
extern struct datatype datatypes[64];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user