Commit 3e2b6a61 authored by rswindell's avatar rswindell
Browse files

Route lputs/lprintf output with a severity level of ERROR (or worse) to the

data/error.log file.
Also, fixed the possible infinite loop in main.cpp output_thread() when send()
fails for the system output socket.
parent 65662f96
......@@ -130,20 +130,26 @@ BOOL dir_op(scfg_t* cfg, user_t* user, uint dirnum)
static int lprintf(int level, const char *fmt, ...)
{
int result;
va_list argptr;
char sbuf[1024];
if(startup==NULL || startup->lputs==NULL || level > startup->log_level)
return(0);
va_start(argptr,fmt);
vsnprintf(sbuf,sizeof(sbuf),fmt,argptr);
sbuf[sizeof(sbuf)-1]=0;
va_end(argptr);
result=startup->lputs(startup->cbdata,level,sbuf);
return(result);
if(level <= LOG_ERR)
errorlog(&scfg,sbuf);
if(startup==NULL || startup->lputs==NULL || level > startup->log_level)
return(0);
#if defined(_WIN32)
if(IsBadCodePtr((FARPROC)startup->lputs))
return(0);
#endif
return startup->lputs(startup->cbdata,level,sbuf);
}
#ifdef _WINSOCKAPI_
......
......@@ -110,6 +110,20 @@ extern "C" BOOL DLLCALL spamlog(scfg_t* cfg, char* prot, char* action
return(TRUE);
}
extern "C" int errorlog(scfg_t* cfg, const char* text)
{
FILE* fp;
char buf[128];
char path[MAX_PATH+1];
sprintf(path,"%serror.log",cfg->logs_dir);
if((fp=fnopen(NULL,path,O_WRONLY|O_CREAT|O_APPEND))==NULL)
return -1;
fprintf(fp,"%s\r\n%s\r\n\r\n",timestr(cfg,time(NULL),buf), text);
fclose(fp);
return 0;
}
void sbbs_t::logentry(const char *code, const char *entry)
{
char str[512];
......@@ -368,12 +382,12 @@ void sbbs_t::errorlog(const char *text)
logline("!!",tmp2);
errorlog_inside=0;
return; }
sprintf(hdr,"%s Node %2d: %s #%d"
sprintf(hdr,"%s\r\nNode %2d: %s #%d\r\n"
,timestr(now),cfg.node_num,useron.alias,useron.number);
write(file,hdr,strlen(hdr));
write(file,crlf,2);
write(file,text,strlen(text));
write(file,"\r\n\r\n",4);
close(file);
errorlog_inside=0;
}
......@@ -128,13 +128,22 @@ static int lprintf(int level, const char *fmt, ...)
va_list argptr;
char sbuf[1024];
if(startup==NULL || startup->lputs==NULL || level > startup->log_level)
return(0);
va_start(argptr,fmt);
vsnprintf(sbuf,sizeof(sbuf),fmt,argptr);
sbuf[sizeof(sbuf)-1]=0;
va_end(argptr);
if(level <= LOG_ERR)
errorlog(&scfg,sbuf);
if(startup==NULL || startup->lputs==NULL || level > startup->log_level)
return(0);
#if defined(_WIN32)
if(IsBadCodePtr((FARPROC)startup->lputs))
return(0);
#endif
return(startup->lputs(startup->cbdata,level,sbuf));
}
......
......@@ -151,9 +151,17 @@ static void thread_down()
int lputs(int level, const char* str)
{
if(level <= LOG_ERR)
errorlog(&scfg,str);
if(startup==NULL || startup->lputs==NULL || str==NULL || level > startup->log_level)
return(0);
#if defined(_WIN32)
if(IsBadCodePtr((FARPROC)startup->lputs))
return(0);
#endif
return(startup->lputs(startup->cbdata,level,str));
}
......@@ -1994,7 +2002,8 @@ void output_thread(void* arg)
,node,ERROR_VALUE,sbbs->client_socket);
if(sbbs->cfg.node_num) /* Only break if node output (not server) */
break;
RingBufReInit(&sbbs->outbuf); /* Flush output buffer */
RingBufReInit(&sbbs->outbuf); /* Purge output ring buffer */
bufbot=buftop=0; /* Purge linear buffer */
continue;
}
if(i<1) {
......
......@@ -905,6 +905,8 @@ extern "C" {
DLLEXPORT char * DLLCALL prep_dir(char* base, char* dir, size_t buflen);
/* logfile.cpp */
DLLEXPORT int DLLCALL errorlog(scfg_t* cfg, const char* text);
DLLEXPORT BOOL DLLCALL hacklog(scfg_t* cfg, char* prot, char* user, char* text
,char* host, SOCKADDR_IN* addr);
DLLEXPORT BOOL DLLCALL spamlog(scfg_t* cfg, char* prot, char* action, char* reason
......
......@@ -119,6 +119,14 @@ static int lprintf(int level, const char *fmt, ...)
va_list argptr;
char sbuf[1024];
va_start(argptr,fmt);
vsnprintf(sbuf,sizeof(sbuf),fmt,argptr);
sbuf[sizeof(sbuf)-1]=0;
va_end(argptr);
if(level <= LOG_ERR)
errorlog(&scfg,sbuf);
if(startup==NULL || startup->lputs==NULL || level > startup->log_level)
return(0);
......@@ -127,10 +135,6 @@ static int lprintf(int level, const char *fmt, ...)
return(0);
#endif
va_start(argptr,fmt);
vsnprintf(sbuf,sizeof(sbuf),fmt,argptr);
sbuf[sizeof(sbuf)-1]=0;
va_end(argptr);
return(startup->lputs(startup->cbdata,level,sbuf));
}
......
......@@ -485,13 +485,22 @@ static int lprintf(int level, const char *fmt, ...)
va_list argptr;
char sbuf[1024];
if(startup==NULL || startup->lputs==NULL || level > startup->log_level)
return(0);
va_start(argptr,fmt);
vsnprintf(sbuf,sizeof(sbuf),fmt,argptr);
sbuf[sizeof(sbuf)-1]=0;
va_end(argptr);
if(level <= LOG_ERR)
errorlog(&scfg,sbuf);
if(startup==NULL || startup->lputs==NULL || level > startup->log_level)
return(0);
#if defined(_WIN32)
if(IsBadCodePtr((FARPROC)startup->lputs))
return(0);
#endif
return(startup->lputs(startup->cbdata,level,sbuf));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment