Check for stopped tasks reverted to the old method without signal handlers

This commit is contained in:
Michiel Broek 2006-05-29 12:28:21 +00:00
parent f50554acfc
commit 725b68c22f
2 changed files with 76 additions and 74 deletions

View File

@ -11,6 +11,8 @@ v0.83.20 27-May-2006
Registration info for the clients was send double coded. Registration info for the clients was send double coded.
Delete users from channel when a server disconnects. Delete users from channel when a server disconnects.
Delete users from a server when server disconnects. Delete users from a server when server disconnects.
Check for stopped tasks reverted to the old method without
signal handlers.
v0.83.19 23-May-2006 - 27-May-2006 v0.83.19 23-May-2006 - 27-May-2006

View File

@ -117,6 +117,8 @@ extern time_t resettime; /* IBC reset time */
int Run_IBC = TRUE; /* Run IBC server */ int Run_IBC = TRUE; /* Run IBC server */
void logtasks(void);
/* /*
* Load main configuration, if it doesn't exist, create it. * Load main configuration, if it doesn't exist, create it.
@ -473,7 +475,7 @@ pid_t launch(char *cmd, char *opts, char *name, int tasktype)
Syslog('?', "Launch: can't execute %s, maximum tasks reached", cmd); Syslog('?', "Launch: can't execute %s, maximum tasks reached", cmd);
return 0; return 0;
} }
// memset(vector, 0, sizeof(vector));
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
vector[i] = NULL; vector[i] = NULL;
@ -554,6 +556,7 @@ pid_t launch(char *cmd, char *opts, char *name, int tasktype)
task[i].running = TRUE; task[i].running = TRUE;
task[i].rc = 0; task[i].rc = 0;
task[i].tasktype = tasktype; task[i].tasktype = tasktype;
logtasks();
break; break;
} }
} }
@ -585,23 +588,18 @@ int runtasktype(int tasktype)
/* void logtasks(void)
* Signal handler for finished tasks
*/
void taskdie(int);
void taskdie(int onsig)
{ {
int i, status; int i, first = TRUE;
for (i = 0; i < MAXTASKS; i++) { if (first) {
if (strlen(task[i].name)) { first = FALSE;
task[i].rc = wait4(task[i].pid, &status, WNOHANG | WUNTRACED, NULL); Syslog('t', "Task Type pid stat rc");
if (task[i].rc) { Syslog('t', "---------------- ------- ----- ---- -----");
task[i].running = FALSE; for (i = 0; i < MAXTASKS; i++)
task[i].status = status; if (strlen(task[i].name))
Syslog('t', "taskdie() set task %d got signal, rc=%d, status=%d", i, task[i].rc, status); Syslog('t', "%-16s %s %5d %s %5d", task[i].name, callmode(task[i].tasktype),
} task[i].pid, task[i].running?"runs":"stop", task[i].rc);
}
} }
} }
@ -614,7 +612,7 @@ void taskdie(int onsig)
*/ */
int checktasks(int onsig) int checktasks(int onsig)
{ {
int i, j, rc, count = 0, first = TRUE; int i, j, rc, count = 0, status;
for (i = 0; i < MAXTASKS; i++) { for (i = 0; i < MAXTASKS; i++) {
if (strlen(task[i].name)) { if (strlen(task[i].name)) {
@ -626,18 +624,22 @@ int checktasks(int onsig)
Syslog('+', "%s to %s (pid %d) failed", SigName[onsig], task[i].name, task[i].pid); Syslog('+', "%s to %s (pid %d) failed", SigName[onsig], task[i].name, task[i].pid);
} }
task[i].rc = wait4(task[i].pid, &status, WNOHANG | WUNTRACED, NULL);
task[i].status = status;
/* /*
* If task was set not running by taskdie(), handle status * If task was set not running, handle status
*/ */
if (task[i].running) { if (task[i].rc) {
count++; task[i].running = FALSE;
} else {
/* /*
* If a mailer call is finished, set the global rescan flag. * If a mailer call is finished, set the global rescan flag.
*/ */
if (task[i].tasktype == CM_POTS || task[i].tasktype == CM_ISDN || task[i].tasktype == CM_INET) if (task[i].tasktype == CM_POTS || task[i].tasktype == CM_ISDN || task[i].tasktype == CM_INET)
rescan = TRUE; rescan = TRUE;
ptimer = PAUSETIME; ptimer = PAUSETIME;
/* /*
* If a nodelist compiler is ready, reload the nodelists configuration * If a nodelist compiler is ready, reload the nodelists configuration
*/ */
@ -646,14 +648,7 @@ int checktasks(int onsig)
initnl(); initnl();
} }
if (first) { logtasks();
first = FALSE;
Syslog('t', "Task Type pid stat");
Syslog('t', "---------------- ------- ----- ----");
for (j = 0; j < MAXTASKS; j++)
if (strlen(task[j].name))
Syslog('t', "%-16s %s %5d %s", task[j].name, callmode(task[j].tasktype),
task[j].pid, task[j].running?"runs":"stop");
} }
switch (task[i].rc) { switch (task[i].rc) {
@ -664,6 +659,11 @@ int checktasks(int onsig)
Syslog('+', "Task %d \"%s\" is ready, error: %s", i, task[i].name, strerror(errno)); Syslog('+', "Task %d \"%s\" is ready, error: %s", i, task[i].name, strerror(errno));
break; break;
case 0: case 0:
/*
* Update last known status when running.
*/
task[i].status = status;
count++;
break; break;
default: default:
if (WIFEXITED(task[i].status)) { if (WIFEXITED(task[i].status)) {
@ -682,12 +682,14 @@ int checktasks(int onsig)
} else if (WIFSTOPPED(task[i].status)) { } else if (WIFSTOPPED(task[i].status)) {
rc = WSTOPSIG(task[i].status); rc = WSTOPSIG(task[i].status);
Syslog('+', "Task %s stopped on signal %s (%d)", task[i].name, SigName[rc], rc); Syslog('+', "Task %s stopped on signal %s (%d)", task[i].name, SigName[rc], rc);
} else {
Syslog('+', "FIXME: 1");
} }
break; break;
} }
/*
* Remove finished task from the list
*/
if (!task[i].running) {
for (j = 0; j < MAXTASKS; j++) { for (j = 0; j < MAXTASKS; j++) {
if (calllist[j].taskpid == task[i].pid) { if (calllist[j].taskpid == task[i].pid) {
calllist[j].calling = FALSE; calllist[j].calling = FALSE;
@ -1128,11 +1130,9 @@ void scheduler(void)
*/ */
do { do {
/* /*
* Poll UNIX Datagram socket and IBC UDP socket until the defined * Poll UNIX Datagram socket and IBC UDP socket until the defined timeout of one second.
* timeout of one second. * This means we listen if a MBSE BBS client program has something to tell us.
* This means we listen if a MBSE BBS client program has something * Timeout is one second, after the timeout the rest of the mainloop is executed.
* to tell. Timeout is one second, after the timeout the rest of the
* mainloop is executed.
*/ */
pfd[0].fd = sock; pfd[0].fd = sock;
pfd[0].events = POLLIN; pfd[0].events = POLLIN;
@ -1560,8 +1560,8 @@ int main(int argc, char **argv)
signal(i, (void (*))die); signal(i, (void (*))die);
else if ((i == SIGINT) || (i == SIGTERM)) else if ((i == SIGINT) || (i == SIGTERM))
signal(i, (void (*))start_shutdown); signal(i, (void (*))start_shutdown);
else if (i == SIGCHLD) else
signal(i, (void (*))taskdie); signal(i, SIG_IGN);
} }
/* /*