diff --git a/src/sbbs3/logfile.cpp b/src/sbbs3/logfile.cpp index 1bf185ef12e8aa40d4ba2fa875d0a2cb25d0899e..1340ddc05d9504d40c5c6553d4b6785a6c41de6b 100644 --- a/src/sbbs3/logfile.cpp +++ b/src/sbbs3/logfile.cpp @@ -241,7 +241,6 @@ void sbbs_t::errormsg(int line, const char *source, const char* action, const ch { const char* src; char str[2048]; - char tmp[512]; /* prevent recursion */ if(errormsg_inside) @@ -250,57 +249,31 @@ void sbbs_t::errormsg(int line, const char *source, const char* action, const ch /* Don't log path to source code */ src=getfname(source); - sprintf(str,"Node %d !ERROR %d " + safe_snprintf(str,sizeof(str),"ERROR %d (%s) " #ifdef _WIN32 - "(WinError %d) " + "(WinError %u) " #endif - "in %s line %d %s \"%s\" access=%ld" - ,cfg.node_num, errno + "in %s line %u %s \"%s\" access=%ld %s%s" + ,errno,STRERROR(errno) #ifdef _WIN32 ,GetLastError() #endif - ,src, line, action, object, access); + ,src, line, action, object, access + ,extinfo==NULL ? "":"info=" + ,extinfo==NULL ? "":extinfo); if(online==ON_LOCAL) eprintf(LOG_ERR,"%s",str); else { - lprintf(LOG_ERR,"%s",str); - bprintf("\7\r\nERROR - action: %s",action); /* tell user about error */ - bprintf("\7\r\n object: %s",object); - bprintf("\7\r\n access: %ld",access); - if(access>9 && (long)access!=-1 && (short)access!=-1 && (char)access!=-1) - bprintf(" (0x%lX)",access); - if(cfg.sys_misc&SM_ERRALARM) { - sbbs_beep(500,220); sbbs_beep(250,220); - sbbs_beep(500,220); sbbs_beep(250,220); - sbbs_beep(500,220); sbbs_beep(250,220); - nosound(); - } - bputs("\r\n\r\nThe sysop has been notified. <Hit a key>"); - getkey(0); + int savatr=curatr; + lprintf(LOG_ERR,"Node %d !%s",cfg.node_num, str); + attr(cfg.color[clr_err]); + bprintf("\7\r\n!ERROR %s %s\r\n", action, object); /* tell user about error */ + bputs("\r\nThe sysop has been notified.\r\n"); + pause(); + attr(savatr); CRLF; } - sprintf(str," source: %s\r\n line: %d\r\n action: %s\r\n" - " object: %s\r\n access: %ld" - ,src,line,action,object,access); - if(access>9 && (long)access!=-1 && (short)access!=-1 && (char)access!=-1) { - sprintf(tmp," (0x%lX)",access); - strcat(str,tmp); - } - if(extinfo!=NULL) { - sprintf(tmp,"\r\n info: %s",extinfo); - strcat(str,tmp); - } - if(errno) { - sprintf(tmp,"\r\n errno: %d (%s)",errno,STRERROR(errno)); - strcat(str,tmp); - errno=0; - } -#if defined(_WIN32) - if(GetLastError()!=0) { - sprintf(tmp,"\r\n WinError: %d (0x%X)",GetLastError(), GetLastError()); - strcat(str,tmp); - } -#endif + safe_snprintf(str,sizeof(str),"ERROR %s %s", action, object); errorlog(str); errormsg_inside=false; } @@ -310,9 +283,6 @@ void sbbs_t::errormsg(int line, const char *source, const char* action, const ch /*****************************************************************************/ void sbbs_t::errorlog(const char *text) { - char hdr[256],str[256],tmp2[256]; - int file; - if(errorlog_inside) /* let's not go recursive on this puppy */ return; errorlog_inside=1; @@ -324,21 +294,14 @@ void sbbs_t::errorlog(const char *text) putnodedat(cfg.node_num,&thisnode); } now=time(NULL); - logline("!!",text); - sprintf(str,"%serror.log",cfg.logs_dir); - if((file=nopen(str,O_WRONLY|O_CREAT|O_APPEND))==-1) { - sprintf(tmp2,"!ERROR %d opening/creating %s",errno,str); - logline("!!",tmp2); - errorlog_inside=0; - return; + if(logfile_fp!=NULL) { + if(logcol!=1) + fprintf(logfile_fp,"\r\n"); + fprintf(logfile_fp,"%!! %s\r\n",text); + logcol=1; + fflush(logfile_fp); } - 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,text,strlen(text)); - write(file,"\r\n\r\n",4); - close(file); errorlog_inside=0; }