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
Branches
Tags
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,21 +373,16 @@ static int ftp_lputs(char *str) ...@@ -370,21 +373,16 @@ static int ftp_lputs(char *str)
time_t t; time_t t;
struct tm* tm_p; struct tm* tm_p;
if(is_daemon) { t=time(NULL);
sprintf(logline,"ftp %.*s",sizeof(logline)-2,str); tm_p=localtime(&t);
} if(tm_p==NULL || is_daemon)
else { tstr[0]=0;
t=time(NULL); else
tm_p=localtime(&t); sprintf(tstr,"%d/%d %02d:%02d:%02d "
if(tm_p==NULL) ,tm_p->tm_mon+1,tm_p->tm_mday
tstr[0]=0; ,tm_p->tm_hour,tm_p->tm_min,tm_p->tm_sec);
else
sprintf(tstr,"%d/%d %02d:%02d:%02d "
,tm_p->tm_mon+1,tm_p->tm_mday
,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,21 +411,16 @@ static int mail_lputs(char *str) ...@@ -413,21 +411,16 @@ static int mail_lputs(char *str)
time_t t; time_t t;
struct tm* tm_p; struct tm* tm_p;
if(is_daemon) { t=time(NULL);
sprintf(logline,"mail %.*s",sizeof(logline)-2,str); tm_p=localtime(&t);
} if(tm_p==NULL || is_daemon)
else { tstr[0]=0;
t=time(NULL); else
tm_p=localtime(&t); sprintf(tstr,"%d/%d %02d:%02d:%02d "
if(tm_p==NULL) ,tm_p->tm_mon+1,tm_p->tm_mday
tstr[0]=0; ,tm_p->tm_hour,tm_p->tm_min,tm_p->tm_sec);
else
sprintf(tstr,"%d/%d %02d:%02d:%02d "
,tm_p->tm_mon+1,tm_p->tm_mday
,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,21 +449,16 @@ static int services_lputs(char *str) ...@@ -456,21 +449,16 @@ static int services_lputs(char *str)
time_t t; time_t t;
struct tm* tm_p; struct tm* tm_p;
if(is_daemon) { t=time(NULL);
sprintf(logline,"srvc %.*s",sizeof(logline)-2,str); tm_p=localtime(&t);
} if(tm_p==NULL || is_daemon)
else { tstr[0]=0;
t=time(NULL); else
tm_p=localtime(&t); sprintf(tstr,"%d/%d %02d:%02d:%02d "
if(tm_p==NULL) ,tm_p->tm_mon+1,tm_p->tm_mday
tstr[0]=0; ,tm_p->tm_hour,tm_p->tm_min,tm_p->tm_sec);
else
sprintf(tstr,"%d/%d %02d:%02d:%02d "
,tm_p->tm_mon+1,tm_p->tm_mday
,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,21 +487,16 @@ static int event_lputs(char *str) ...@@ -499,21 +487,16 @@ static int event_lputs(char *str)
time_t t; time_t t;
struct tm* tm_p; struct tm* tm_p;
if(is_daemon) { t=time(NULL);
sprintf(logline,"evnt %.*s",sizeof(logline)-2,str); tm_p=localtime(&t);
} if(tm_p==NULL || is_daemon)
else { tstr[0]=0;
t=time(NULL); else
tm_p=localtime(&t); sprintf(tstr,"%d/%d %02d:%02d:%02d "
if(tm_p==NULL) ,tm_p->tm_mon+1,tm_p->tm_mday
tstr[0]=0; ,tm_p->tm_hour,tm_p->tm_min,tm_p->tm_sec);
else
sprintf(tstr,"%d/%d %02d:%02d:%02d "
,tm_p->tm_mon+1,tm_p->tm_mday
,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,9 +950,11 @@ int main(int argc, char** argv) ...@@ -967,9 +950,11 @@ 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");
fprintf(pidfile,"%d",getpid()); if(pidfile!=NULL) {
fclose(pidfile); fprintf(pidfile,"%d",getpid());
fclose(pidfile);
}
} }
#endif #endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment