Fixes for mbtask

This commit is contained in:
Michiel Broek 2003-01-27 21:55:42 +00:00
parent d200e2c1b4
commit 8c5034f00f
4 changed files with 164 additions and 144 deletions

View File

@ -29,6 +29,9 @@ v0.37.01 14-Jan-2003.
Fixed a bug where one of the nodelists was node closed with
each outbound scan and was causing mbtask to stop functioning
after a few days.
After forking the daemon, the stdin, stdout and stderr are
reopend to /dev/null.
Zero the daily status counters finally works again.
mbfile:
In the import function several bugfixes for reading files.bbs.

4
TODO
View File

@ -93,6 +93,10 @@ mbfido:
N: Let mbfido areas with a special switch update area descriptions.
N: Send rulefile via netmail for each new connected mail area.
N: Send notifications to downlinks about changed areas from uplink.
mbcico:
N: Implement MD5 crypt in binkp protocol driver.

View File

@ -1258,126 +1258,138 @@ void scheduler(void)
int main(int argc, char **argv)
{
struct passwd *pw;
int i;
pid_t frk;
FILE *fp;
struct passwd *pw;
int i;
pid_t frk;
FILE *fp;
/*
* Print copyright notices and setup logging.
*/
printf("MBTASK: MBSE BBS v%s Task Manager Daemon\n", VERSION);
printf(" %s\n\n", COPYRIGHT);
/*
* Print copyright notices and setup logging.
*/
printf("MBTASK: MBSE BBS v%s Task Manager Daemon\n", VERSION);
printf(" %s\n\n", COPYRIGHT);
/*
* Catch all the signals we can, and ignore the rest. Note that SIGKILL can't be ignored
* but that's live. This daemon should only be stopped by SIGTERM.
*/
for(i = 0; i < NSIG; i++) {
if ((i == SIGHUP) || (i == SIGINT) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM))
signal(i, (void (*))die);
else
signal(i, SIG_IGN);
}
/*
* Catch all the signals we can, and ignore the rest. Note that SIGKILL can't be ignored
* but that's live. This daemon should only be stopped by SIGTERM.
*/
for (i = 0; i < NSIG; i++) {
if ((i == SIGHUP) || (i == SIGINT) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM))
signal(i, (void (*))die);
else
signal(i, SIG_IGN);
}
init_pingsocket();
init_pingsocket();
/*
* mbtask is setuid root, drop privileges to user mbse.
* This will stay forever like this, no need to become
* root again. The child can't even become root anymore.
*/
pw = getpwnam((char *)"mbse");
if (setuid(pw->pw_uid)) {
perror("");
printf("can't setuid to mbse\n");
close(ping_isocket);
exit(MBERR_INIT_ERROR);
}
if (setgid(pw->pw_gid)) {
perror("");
printf("can't setgid to bbs\n");
close(ping_isocket);
exit(MBERR_INIT_ERROR);
}
/*
* mbtask is setuid root, drop privileges to user mbse.
* This will stay forever like this, no need to become
* root again. The child can't even become root anymore.
*/
pw = getpwnam((char *)"mbse");
if (setuid(pw->pw_uid)) {
perror("");
fprintf(stderr, "can't setuid to mbse\n");
close(ping_isocket);
exit(MBERR_INIT_ERROR);
}
if (setgid(pw->pw_gid)) {
perror("");
fprintf(stderr, "can't setgid to bbs\n");
close(ping_isocket);
exit(MBERR_INIT_ERROR);
}
umask(007);
if (locktask(pw->pw_dir)) {
close(ping_isocket);
exit(MBERR_NO_PROGLOCK);
}
umask(007);
if (locktask(pw->pw_dir)) {
close(ping_isocket);
exit(MBERR_NO_PROGLOCK);
}
sprintf(cfgfn, "%s/etc/config.data", getenv("MBSE_ROOT"));
load_maincfg();
sprintf(cfgfn, "%s/etc/config.data", getenv("MBSE_ROOT"));
load_maincfg();
Syslog(' ', " ");
Syslog(' ', "MBTASK v%s", VERSION);
sprintf(tcfgfn, "%s/etc/task.data", getenv("MBSE_ROOT"));
load_taskcfg();
status_init();
Syslog(' ', " ");
Syslog(' ', "MBTASK v%s", VERSION);
sprintf(tcfgfn, "%s/etc/task.data", getenv("MBSE_ROOT"));
load_taskcfg();
status_init();
memset(&task, 0, sizeof(task));
memset(&reginfo, 0, sizeof(reginfo));
memset(&calllist, 0, sizeof(calllist));
sprintf(spath, "%s/tmp/mbtask", getenv("MBSE_ROOT"));
sprintf(ttyfn, "%s/etc/ttyinfo.data", getenv("MBSE_ROOT"));
initnl();
load_ports();
check_ports();
memset(&task, 0, sizeof(task));
memset(&reginfo, 0, sizeof(reginfo));
memset(&calllist, 0, sizeof(calllist));
sprintf(spath, "%s/tmp/mbtask", getenv("MBSE_ROOT"));
sprintf(ttyfn, "%s/etc/ttyinfo.data", getenv("MBSE_ROOT"));
initnl();
load_ports();
check_ports();
/*
* Now that init is complete and this program is locked, it is
* safe to remove a stale socket if it is there after a crash.
*/
if (!file_exist(spath, R_OK))
unlink(spath);
/*
* Now that init is complete and this program is locked, it is
* safe to remove a stale socket if it is there after a crash.
*/
if (!file_exist(spath, R_OK))
unlink(spath);
/*
* Server initialization is complete. Now we can fork the
* daemon and return to the user. We need to do a setpgrp
* so that the daemon will no longer be assosiated with the
* users control terminal. This is done before the fork, so
* that the child will not be a process group leader. Otherwise,
* if the child were to open a terminal, it would become
* associated with that terminal as its control terminal.
*/
if ((pgrp = setpgid(0, 0)) == -1) {
Syslog('?', "$setpgid failed");
die(MBERR_INIT_ERROR);
}
/*
* Server initialization is complete. Now we can fork the
* daemon and return to the user. We need to do a setpgrp
* so that the daemon will no longer be assosiated with the
* users control terminal. This is done before the fork, so
* that the child will not be a process group leader. Otherwise,
* if the child were to open a terminal, it would become
* associated with that terminal as its control terminal.
*/
if ((pgrp = setpgid(0, 0)) == -1) {
Syslog('?', "$setpgid failed");
die(MBERR_INIT_ERROR);
}
frk = fork();
switch (frk) {
case -1:
Syslog('?', "$Unable to fork daemon");
die(MBERR_INIT_ERROR);
case 0:
/*
* Starting the deamon child process here.
*/
fclose(stdin);
fclose(stdout);
fclose(stderr);
scheduler();
/* Not reached */
default:
/*
* Here we detach this process and let the child
* run the deamon process. Put the child's pid
* in the lockfile before leaving.
*/
if ((fp = fopen(lockfile, "w"))) {
fprintf(fp, "%10u\n", frk);
fclose(fp);
}
Syslog('+', "Starting daemon with pid %d", frk);
exit(MBERR_OK);
}
frk = fork();
switch (frk) {
case -1:
Syslog('?', "$Unable to fork daemon");
die(MBERR_INIT_ERROR);
case 0:
/*
* Starting the deamon child process here.
*/
fclose(stdin);
if (open("/dev/null", O_RDONLY) != 0) {
Syslog('?', "$Reopen of stdin to /dev/null failed");
_exit(MBERR_EXEC_FAILED);
}
fclose(stdout);
if (open("/dev/null", O_WRONLY | O_APPEND | O_CREAT,0600) != 1) {
Syslog('?', "$Reopen of stdout to /dev/null failed");
_exit(MBERR_EXEC_FAILED);
}
fclose(stderr);
if (open("/dev/null", O_WRONLY | O_APPEND | O_CREAT,0600) != 2) {
Syslog('?', "$Reopen of stderr to /dev/null failed");
_exit(MBERR_EXEC_FAILED);
}
scheduler();
/* Not reached */
default:
/*
* Here we detach this process and let the child
* run the deamon process. Put the child's pid
* in the lockfile before leaving.
*/
if ((fp = fopen(lockfile, "w"))) {
fprintf(fp, "%10u\n", frk);
fclose(fp);
}
Syslog('+', "Starting daemon with pid %d", frk);
exit(MBERR_OK);
}
/*
* Not reached
*/
return 0;
/*
* Not reached
*/
return 0;
}

View File

@ -143,49 +143,50 @@ void status_init()
void status_write(void);
void status_write(void)
{
int d, stat_fd;
struct tm *ttm, *ytm;
time_t temp;
int d, stat_fd, yday;
struct tm *ttm;
time_t temp;
temp = time(NULL);
ttm = localtime(&temp);
temp = status.daily; // On a Sparc, first put the time in temp, then pass it to locattime.
ytm = localtime(&temp);
temp = time(NULL);
ttm = localtime(&temp);
yday = ttm->tm_yday;
temp = status.daily; // On a Sparc, first put the time in temp, then pass it to locattime.
ttm = localtime(&temp);
/*
* If we passed to the next day, zero the today counters
*/
if (ttm->tm_yday != ytm->tm_yday) {
Syslog('+', "Last days statistics:");
Syslog('+', "Total clients : %lu", status.today.tot_clt);
Syslog('+', "Peak clients : %lu", status.today.peak_clt);
Syslog('+', "Syntax errors : %lu", status.today.s_error);
Syslog('+', "Comms errors : %lu", status.today.c_error);
/*
* If we passed to the next day, zero the today counters
*/
if (yday != ttm->tm_yday) {
Syslog('+', "Last days statistics:");
Syslog('+', "Total clients : %lu", status.today.tot_clt);
Syslog('+', "Peak clients : %lu", status.today.peak_clt);
Syslog('+', "Syntax errors : %lu", status.today.s_error);
Syslog('+', "Comms errors : %lu", status.today.c_error);
memset((char *)&status.today, 0, sizeof(cl_stat));
status.daily = time(NULL);
Syslog('+', "Zeroed todays status counters");
}
memset((char *)&status.today, 0, sizeof(cl_stat));
status.daily = time(NULL);
Syslog('+', "Zeroed todays status counters");
}
if ((stat_fd = open(stat_fn, O_RDWR)) == -1) {
Syslog('?', "$Error open statusfile %s", stat_fn);
return;
}
if ((stat_fd = open(stat_fn, O_RDWR)) == -1) {
Syslog('?', "$Error open statusfile %s", stat_fn);
return;
}
if ((d = lseek(stat_fd, 0, SEEK_SET)) != 0) {
Syslog('?', "$Error seeking in statusfile");
return;
}
if ((d = lseek(stat_fd, 0, SEEK_SET)) != 0) {
Syslog('?', "$Error seeking in statusfile");
return;
}
d = write(stat_fd, &status, sizeof(status_r));
if (d != sizeof(status_r))
Syslog('?', "$Error writing statusfile, only %d bytes", d);
d = write(stat_fd, &status, sizeof(status_r));
if (d != sizeof(status_r))
Syslog('?', "$Error writing statusfile, only %d bytes", d);
/*
* CLose the statusfile
*/
if (close(stat_fd) != 0)
Syslog('?', "$Error closing statusfile");
/*
* CLose the statusfile
*/
if (close(stat_fd) != 0)
Syslog('?', "$Error closing statusfile");
}