Fixes for mbtask
This commit is contained in:
parent
d200e2c1b4
commit
8c5034f00f
@ -29,6 +29,9 @@ v0.37.01 14-Jan-2003.
|
|||||||
Fixed a bug where one of the nodelists was node closed with
|
Fixed a bug where one of the nodelists was node closed with
|
||||||
each outbound scan and was causing mbtask to stop functioning
|
each outbound scan and was causing mbtask to stop functioning
|
||||||
after a few days.
|
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:
|
mbfile:
|
||||||
In the import function several bugfixes for reading files.bbs.
|
In the import function several bugfixes for reading files.bbs.
|
||||||
|
4
TODO
4
TODO
@ -93,6 +93,10 @@ mbfido:
|
|||||||
|
|
||||||
N: Let mbfido areas with a special switch update area descriptions.
|
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:
|
mbcico:
|
||||||
N: Implement MD5 crypt in binkp protocol driver.
|
N: Implement MD5 crypt in binkp protocol driver.
|
||||||
|
|
||||||
|
228
mbtask/mbtask.c
228
mbtask/mbtask.c
@ -1258,126 +1258,138 @@ void scheduler(void)
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
int i;
|
int i;
|
||||||
pid_t frk;
|
pid_t frk;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Print copyright notices and setup logging.
|
* Print copyright notices and setup logging.
|
||||||
*/
|
*/
|
||||||
printf("MBTASK: MBSE BBS v%s Task Manager Daemon\n", VERSION);
|
printf("MBTASK: MBSE BBS v%s Task Manager Daemon\n", VERSION);
|
||||||
printf(" %s\n\n", COPYRIGHT);
|
printf(" %s\n\n", COPYRIGHT);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Catch all the signals we can, and ignore the rest. Note that SIGKILL can't be ignored
|
* 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.
|
* but that's live. This daemon should only be stopped by SIGTERM.
|
||||||
*/
|
*/
|
||||||
for(i = 0; i < NSIG; i++) {
|
for (i = 0; i < NSIG; i++) {
|
||||||
if ((i == SIGHUP) || (i == SIGINT) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM))
|
if ((i == SIGHUP) || (i == SIGINT) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM))
|
||||||
signal(i, (void (*))die);
|
signal(i, (void (*))die);
|
||||||
else
|
else
|
||||||
signal(i, SIG_IGN);
|
signal(i, SIG_IGN);
|
||||||
}
|
}
|
||||||
|
|
||||||
init_pingsocket();
|
init_pingsocket();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* mbtask is setuid root, drop privileges to user mbse.
|
* mbtask is setuid root, drop privileges to user mbse.
|
||||||
* This will stay forever like this, no need to become
|
* This will stay forever like this, no need to become
|
||||||
* root again. The child can't even become root anymore.
|
* root again. The child can't even become root anymore.
|
||||||
*/
|
*/
|
||||||
pw = getpwnam((char *)"mbse");
|
pw = getpwnam((char *)"mbse");
|
||||||
if (setuid(pw->pw_uid)) {
|
if (setuid(pw->pw_uid)) {
|
||||||
perror("");
|
perror("");
|
||||||
printf("can't setuid to mbse\n");
|
fprintf(stderr, "can't setuid to mbse\n");
|
||||||
close(ping_isocket);
|
close(ping_isocket);
|
||||||
exit(MBERR_INIT_ERROR);
|
exit(MBERR_INIT_ERROR);
|
||||||
}
|
}
|
||||||
if (setgid(pw->pw_gid)) {
|
if (setgid(pw->pw_gid)) {
|
||||||
perror("");
|
perror("");
|
||||||
printf("can't setgid to bbs\n");
|
fprintf(stderr, "can't setgid to bbs\n");
|
||||||
close(ping_isocket);
|
close(ping_isocket);
|
||||||
exit(MBERR_INIT_ERROR);
|
exit(MBERR_INIT_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
umask(007);
|
umask(007);
|
||||||
if (locktask(pw->pw_dir)) {
|
if (locktask(pw->pw_dir)) {
|
||||||
close(ping_isocket);
|
close(ping_isocket);
|
||||||
exit(MBERR_NO_PROGLOCK);
|
exit(MBERR_NO_PROGLOCK);
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(cfgfn, "%s/etc/config.data", getenv("MBSE_ROOT"));
|
sprintf(cfgfn, "%s/etc/config.data", getenv("MBSE_ROOT"));
|
||||||
load_maincfg();
|
load_maincfg();
|
||||||
|
|
||||||
Syslog(' ', " ");
|
Syslog(' ', " ");
|
||||||
Syslog(' ', "MBTASK v%s", VERSION);
|
Syslog(' ', "MBTASK v%s", VERSION);
|
||||||
sprintf(tcfgfn, "%s/etc/task.data", getenv("MBSE_ROOT"));
|
sprintf(tcfgfn, "%s/etc/task.data", getenv("MBSE_ROOT"));
|
||||||
load_taskcfg();
|
load_taskcfg();
|
||||||
status_init();
|
status_init();
|
||||||
|
|
||||||
memset(&task, 0, sizeof(task));
|
memset(&task, 0, sizeof(task));
|
||||||
memset(®info, 0, sizeof(reginfo));
|
memset(®info, 0, sizeof(reginfo));
|
||||||
memset(&calllist, 0, sizeof(calllist));
|
memset(&calllist, 0, sizeof(calllist));
|
||||||
sprintf(spath, "%s/tmp/mbtask", getenv("MBSE_ROOT"));
|
sprintf(spath, "%s/tmp/mbtask", getenv("MBSE_ROOT"));
|
||||||
sprintf(ttyfn, "%s/etc/ttyinfo.data", getenv("MBSE_ROOT"));
|
sprintf(ttyfn, "%s/etc/ttyinfo.data", getenv("MBSE_ROOT"));
|
||||||
initnl();
|
initnl();
|
||||||
load_ports();
|
load_ports();
|
||||||
check_ports();
|
check_ports();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now that init is complete and this program is locked, it is
|
* 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.
|
* safe to remove a stale socket if it is there after a crash.
|
||||||
*/
|
*/
|
||||||
if (!file_exist(spath, R_OK))
|
if (!file_exist(spath, R_OK))
|
||||||
unlink(spath);
|
unlink(spath);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Server initialization is complete. Now we can fork the
|
* Server initialization is complete. Now we can fork the
|
||||||
* daemon and return to the user. We need to do a setpgrp
|
* daemon and return to the user. We need to do a setpgrp
|
||||||
* so that the daemon will no longer be assosiated with the
|
* so that the daemon will no longer be assosiated with the
|
||||||
* users control terminal. This is done before the fork, so
|
* users control terminal. This is done before the fork, so
|
||||||
* that the child will not be a process group leader. Otherwise,
|
* that the child will not be a process group leader. Otherwise,
|
||||||
* if the child were to open a terminal, it would become
|
* if the child were to open a terminal, it would become
|
||||||
* associated with that terminal as its control terminal.
|
* associated with that terminal as its control terminal.
|
||||||
*/
|
*/
|
||||||
if ((pgrp = setpgid(0, 0)) == -1) {
|
if ((pgrp = setpgid(0, 0)) == -1) {
|
||||||
Syslog('?', "$setpgid failed");
|
Syslog('?', "$setpgid failed");
|
||||||
die(MBERR_INIT_ERROR);
|
die(MBERR_INIT_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
frk = fork();
|
frk = fork();
|
||||||
switch (frk) {
|
switch (frk) {
|
||||||
case -1:
|
case -1:
|
||||||
Syslog('?', "$Unable to fork daemon");
|
Syslog('?', "$Unable to fork daemon");
|
||||||
die(MBERR_INIT_ERROR);
|
die(MBERR_INIT_ERROR);
|
||||||
case 0:
|
case 0:
|
||||||
/*
|
/*
|
||||||
* Starting the deamon child process here.
|
* Starting the deamon child process here.
|
||||||
*/
|
*/
|
||||||
fclose(stdin);
|
fclose(stdin);
|
||||||
fclose(stdout);
|
if (open("/dev/null", O_RDONLY) != 0) {
|
||||||
fclose(stderr);
|
Syslog('?', "$Reopen of stdin to /dev/null failed");
|
||||||
scheduler();
|
_exit(MBERR_EXEC_FAILED);
|
||||||
/* Not reached */
|
}
|
||||||
default:
|
fclose(stdout);
|
||||||
/*
|
if (open("/dev/null", O_WRONLY | O_APPEND | O_CREAT,0600) != 1) {
|
||||||
* Here we detach this process and let the child
|
Syslog('?', "$Reopen of stdout to /dev/null failed");
|
||||||
* run the deamon process. Put the child's pid
|
_exit(MBERR_EXEC_FAILED);
|
||||||
* in the lockfile before leaving.
|
}
|
||||||
*/
|
fclose(stderr);
|
||||||
if ((fp = fopen(lockfile, "w"))) {
|
if (open("/dev/null", O_WRONLY | O_APPEND | O_CREAT,0600) != 2) {
|
||||||
fprintf(fp, "%10u\n", frk);
|
Syslog('?', "$Reopen of stderr to /dev/null failed");
|
||||||
fclose(fp);
|
_exit(MBERR_EXEC_FAILED);
|
||||||
}
|
}
|
||||||
Syslog('+', "Starting daemon with pid %d", frk);
|
scheduler();
|
||||||
exit(MBERR_OK);
|
/* 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
|
* Not reached
|
||||||
*/
|
*/
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -143,49 +143,50 @@ void status_init()
|
|||||||
void status_write(void);
|
void status_write(void);
|
||||||
void status_write(void)
|
void status_write(void)
|
||||||
{
|
{
|
||||||
int d, stat_fd;
|
int d, stat_fd, yday;
|
||||||
struct tm *ttm, *ytm;
|
struct tm *ttm;
|
||||||
time_t temp;
|
time_t temp;
|
||||||
|
|
||||||
temp = time(NULL);
|
temp = time(NULL);
|
||||||
ttm = localtime(&temp);
|
ttm = localtime(&temp);
|
||||||
temp = status.daily; // On a Sparc, first put the time in temp, then pass it to locattime.
|
yday = ttm->tm_yday;
|
||||||
ytm = localtime(&temp);
|
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 we passed to the next day, zero the today counters
|
||||||
*/
|
*/
|
||||||
if (ttm->tm_yday != ytm->tm_yday) {
|
if (yday != ttm->tm_yday) {
|
||||||
Syslog('+', "Last days statistics:");
|
Syslog('+', "Last days statistics:");
|
||||||
Syslog('+', "Total clients : %lu", status.today.tot_clt);
|
Syslog('+', "Total clients : %lu", status.today.tot_clt);
|
||||||
Syslog('+', "Peak clients : %lu", status.today.peak_clt);
|
Syslog('+', "Peak clients : %lu", status.today.peak_clt);
|
||||||
Syslog('+', "Syntax errors : %lu", status.today.s_error);
|
Syslog('+', "Syntax errors : %lu", status.today.s_error);
|
||||||
Syslog('+', "Comms errors : %lu", status.today.c_error);
|
Syslog('+', "Comms errors : %lu", status.today.c_error);
|
||||||
|
|
||||||
memset((char *)&status.today, 0, sizeof(cl_stat));
|
memset((char *)&status.today, 0, sizeof(cl_stat));
|
||||||
status.daily = time(NULL);
|
status.daily = time(NULL);
|
||||||
Syslog('+', "Zeroed todays status counters");
|
Syslog('+', "Zeroed todays status counters");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((stat_fd = open(stat_fn, O_RDWR)) == -1) {
|
if ((stat_fd = open(stat_fn, O_RDWR)) == -1) {
|
||||||
Syslog('?', "$Error open statusfile %s", stat_fn);
|
Syslog('?', "$Error open statusfile %s", stat_fn);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((d = lseek(stat_fd, 0, SEEK_SET)) != 0) {
|
if ((d = lseek(stat_fd, 0, SEEK_SET)) != 0) {
|
||||||
Syslog('?', "$Error seeking in statusfile");
|
Syslog('?', "$Error seeking in statusfile");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
d = write(stat_fd, &status, sizeof(status_r));
|
d = write(stat_fd, &status, sizeof(status_r));
|
||||||
if (d != sizeof(status_r))
|
if (d != sizeof(status_r))
|
||||||
Syslog('?', "$Error writing statusfile, only %d bytes", d);
|
Syslog('?', "$Error writing statusfile, only %d bytes", d);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CLose the statusfile
|
* CLose the statusfile
|
||||||
*/
|
*/
|
||||||
if (close(stat_fd) != 0)
|
if (close(stat_fd) != 0)
|
||||||
Syslog('?', "$Error closing statusfile");
|
Syslog('?', "$Error closing statusfile");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user