Skip to content
Snippets Groups Projects
Commit a8c37e07 authored by rswindell's avatar rswindell
Browse files

Simplified the "is_daemon" portion of the various xxx_lputs routines.

Created macro for pid filename.
parent b6e3c9eb
No related branches found
No related tags found
No related merge requests found
...@@ -59,6 +59,9 @@ ...@@ -59,6 +59,9 @@
#endif #endif
/* Constants */
#define SBBS_PID_FILE "/var/run/sbbs.pid"
/* Global variables */ /* Global variables */
BOOL bbs_running=FALSE; BOOL bbs_running=FALSE;
BOOL bbs_stopped=FALSE; BOOL bbs_stopped=FALSE;
...@@ -370,13 +373,9 @@ static int ftp_lputs(char *str) ...@@ -370,13 +373,9 @@ static int ftp_lputs(char *str)
time_t t; time_t t;
struct tm* tm_p; struct tm* tm_p;
if(is_daemon) {
sprintf(logline,"ftp %.*s",sizeof(logline)-2,str);
}
else {
t=time(NULL); t=time(NULL);
tm_p=localtime(&t); tm_p=localtime(&t);
if(tm_p==NULL) if(tm_p==NULL || is_daemon)
tstr[0]=0; tstr[0]=0;
else else
sprintf(tstr,"%d/%d %02d:%02d:%02d " sprintf(tstr,"%d/%d %02d:%02d:%02d "
...@@ -384,7 +383,6 @@ static int ftp_lputs(char *str) ...@@ -384,7 +383,6 @@ static int ftp_lputs(char *str)
,tm_p->tm_hour,tm_p->tm_min,tm_p->tm_sec); ,tm_p->tm_hour,tm_p->tm_min,tm_p->tm_sec);
sprintf(logline,"%sftp %.*s",tstr,sizeof(logline)-2,str); sprintf(logline,"%sftp %.*s",tstr,sizeof(logline)-2,str);
}
truncsp(logline); truncsp(logline);
lputs(logline); lputs(logline);
...@@ -413,13 +411,9 @@ static int mail_lputs(char *str) ...@@ -413,13 +411,9 @@ static int mail_lputs(char *str)
time_t t; time_t t;
struct tm* tm_p; struct tm* tm_p;
if(is_daemon) {
sprintf(logline,"mail %.*s",sizeof(logline)-2,str);
}
else {
t=time(NULL); t=time(NULL);
tm_p=localtime(&t); tm_p=localtime(&t);
if(tm_p==NULL) if(tm_p==NULL || is_daemon)
tstr[0]=0; tstr[0]=0;
else else
sprintf(tstr,"%d/%d %02d:%02d:%02d " sprintf(tstr,"%d/%d %02d:%02d:%02d "
...@@ -427,7 +421,6 @@ static int mail_lputs(char *str) ...@@ -427,7 +421,6 @@ static int mail_lputs(char *str)
,tm_p->tm_hour,tm_p->tm_min,tm_p->tm_sec); ,tm_p->tm_hour,tm_p->tm_min,tm_p->tm_sec);
sprintf(logline,"%smail %.*s",tstr,sizeof(logline)-2,str); sprintf(logline,"%smail %.*s",tstr,sizeof(logline)-2,str);
}
truncsp(logline); truncsp(logline);
lputs(logline); lputs(logline);
...@@ -456,13 +449,9 @@ static int services_lputs(char *str) ...@@ -456,13 +449,9 @@ static int services_lputs(char *str)
time_t t; time_t t;
struct tm* tm_p; struct tm* tm_p;
if(is_daemon) {
sprintf(logline,"srvc %.*s",sizeof(logline)-2,str);
}
else {
t=time(NULL); t=time(NULL);
tm_p=localtime(&t); tm_p=localtime(&t);
if(tm_p==NULL) if(tm_p==NULL || is_daemon)
tstr[0]=0; tstr[0]=0;
else else
sprintf(tstr,"%d/%d %02d:%02d:%02d " sprintf(tstr,"%d/%d %02d:%02d:%02d "
...@@ -470,7 +459,6 @@ static int services_lputs(char *str) ...@@ -470,7 +459,6 @@ static int services_lputs(char *str)
,tm_p->tm_hour,tm_p->tm_min,tm_p->tm_sec); ,tm_p->tm_hour,tm_p->tm_min,tm_p->tm_sec);
sprintf(logline,"%ssrvc %.*s",tstr,sizeof(logline)-2,str); sprintf(logline,"%ssrvc %.*s",tstr,sizeof(logline)-2,str);
}
truncsp(logline); truncsp(logline);
lputs(logline); lputs(logline);
...@@ -499,13 +487,9 @@ static int event_lputs(char *str) ...@@ -499,13 +487,9 @@ static int event_lputs(char *str)
time_t t; time_t t;
struct tm* tm_p; struct tm* tm_p;
if(is_daemon) {
sprintf(logline,"evnt %.*s",sizeof(logline)-2,str);
}
else {
t=time(NULL); t=time(NULL);
tm_p=localtime(&t); tm_p=localtime(&t);
if(tm_p==NULL) if(tm_p==NULL || is_daemon)
tstr[0]=0; tstr[0]=0;
else else
sprintf(tstr,"%d/%d %02d:%02d:%02d " sprintf(tstr,"%d/%d %02d:%02d:%02d "
...@@ -513,7 +497,6 @@ static int event_lputs(char *str) ...@@ -513,7 +497,6 @@ static int event_lputs(char *str)
,tm_p->tm_hour,tm_p->tm_min,tm_p->tm_sec); ,tm_p->tm_hour,tm_p->tm_min,tm_p->tm_sec);
sprintf(logline,"%sevnt %.*s",tstr,sizeof(logline)-2,str); sprintf(logline,"%sevnt %.*s",tstr,sizeof(logline)-2,str);
}
truncsp(logline); truncsp(logline);
lputs(logline); lputs(logline);
...@@ -532,7 +515,7 @@ void _sighandler_quit(int sig) ...@@ -532,7 +515,7 @@ void _sighandler_quit(int sig)
while(bbs_running || ftp_running || mail_running || services_running) while(bbs_running || ftp_running || mail_running || services_running)
mswait(1); mswait(1);
if(is_daemon) if(is_daemon)
unlink("/var/run/sbbs.pid"); unlink(SBBS_PID_FILE);
exit(0); exit(0);
} }
...@@ -967,10 +950,12 @@ int main(int argc, char** argv) ...@@ -967,10 +950,12 @@ int main(int argc, char** argv)
#ifdef __unix__ #ifdef __unix__
/* Write the standard .pid file if running as a daemon */ /* Write the standard .pid file if running as a daemon */
if(is_daemon) { if(is_daemon) {
pidfile=fopen("/var/run/sbbs.pid","w"); pidfile=fopen(SBBS_PID_FILE,"w");
if(pidfile!=NULL) {
fprintf(pidfile,"%d",getpid()); fprintf(pidfile,"%d",getpid());
fclose(pidfile); fclose(pidfile);
} }
}
#endif #endif
_beginthread((void(*)(void*))bbs_thread,0,&bbs_startup); _beginthread((void(*)(void*))bbs_thread,0,&bbs_startup);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment