Finished new task handling

This commit is contained in:
Michiel Broek 2006-02-04 13:56:21 +00:00
parent a41d4dab47
commit 0ed5a3527d

View File

@ -544,13 +544,13 @@ pid_t launch(char *cmd, char *opts, char *name, int tasktype)
*/ */
int runtasktype(int tasktype) int runtasktype(int tasktype)
{ {
int i, count = 0; int i, count = 0;
for (i = 0; i < MAXTASKS; i++) { for (i = 0; i < MAXTASKS; i++) {
if (strlen(task[i].name) && task[i].running && (task[i].tasktype == tasktype)) if (strlen(task[i].name) && task[i].running && (task[i].tasktype == tasktype))
count++; count++;
} }
return count; return count;
} }
@ -563,15 +563,13 @@ void taskdie(int onsig)
{ {
int i, status; int i, status;
Syslog('t', "taskdie(%s)", SigName[onsig]);
for (i = 0; i < MAXTASKS; i++) { for (i = 0; i < MAXTASKS; i++) {
if (strlen(task[i].name)) { if (strlen(task[i].name)) {
task[i].rc = wait4(task[i].pid, &status, WNOHANG | WUNTRACED, NULL); task[i].rc = wait4(task[i].pid, &status, WNOHANG | WUNTRACED, NULL);
if (task[i].rc) { if (task[i].rc) {
task[i].running = FALSE; task[i].running = FALSE;
task[i].status = status; task[i].status = status;
Syslog('t', "taskdie() set task %d not running, rc=%d, status=%d", i, task[i].rc, status); Syslog('t', "taskdie() set task %d got signal, rc=%d, status=%d", i, task[i].rc, status);
} }
} }
} }
@ -598,11 +596,12 @@ 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); /*
// if (task[i].rc) { * If task was set not running by taskdie(), handle status
// task[i].running = FALSE; */
if (task[i].running) {
if (task[i].running == FALSE) { count++;
} else {
/* /*
* If a mailer call is finished, set the global rescan flag. * If a mailer call is finished, set the global rescan flag.
*/ */
@ -616,56 +615,49 @@ int checktasks(int onsig)
deinitnl(); deinitnl();
initnl(); initnl();
} }
}
if (first && task[i].rc) { if (first) {
first = FALSE; first = FALSE;
Syslog('t', "Task Type pid stat"); Syslog('t', "Task Type pid stat");
Syslog('t', "---------------- ------- ----- ----"); Syslog('t', "---------------- ------- ----- ----");
for (j = 0; j < MAXTASKS; j++) for (j = 0; j < MAXTASKS; j++)
if (strlen(task[j].name)) if (strlen(task[j].name))
Syslog('t', "%-16s %s %5d %s", task[j].name, callmode(task[j].tasktype), Syslog('t', "%-16s %s %5d %s", task[j].name, callmode(task[j].tasktype),
task[j].pid, task[j].running?"runs":"stop"); task[j].pid, task[j].running?"runs":"stop");
} }
switch (task[i].rc) { switch (task[i].rc) {
case -1: case -1:
if (errno == ECHILD) if (errno == ECHILD)
Syslog('+', "Task %d \"%s\" is ready", i, task[i].name); Syslog('+', "Task %d \"%s\" is ready", i, task[i].name);
else
Syslog('+', "Task %d \"%s\" is ready, error: %s", i, task[i].name, strerror(errno));
break;
case 0:
/*
* Update last known status when running.
*/
// task[i].status = status;
count++;
break;
default:
if (WIFEXITED(task[i].status)) {
rc = WEXITSTATUS(task[i].status);
if (rc)
Syslog('+', "Task %s is ready, error=%d", task[i].name, rc);
else else
Syslog('+', "Task %s is ready", task[i].name); Syslog('+', "Task %d \"%s\" is ready, error: %s", i, task[i].name, strerror(errno));
} else if (WIFSIGNALED(task[i].status)) { break;
rc = WTERMSIG(task[i].status); case 0:
/* break;
* Here we don't report an error number, on FreeBSD WIFSIGNALED default:
* seems true while there's nothing wrong. if (WIFEXITED(task[i].status)) {
*/ rc = WEXITSTATUS(task[i].status);
Syslog('+', "Task %s terminated", task[i].name); if (rc)
} else if (WIFSTOPPED(task[i].status)) { Syslog('+', "Task %s is ready, error=%d", task[i].name, rc);
rc = WSTOPSIG(task[i].status); else
Syslog('+', "Task %s stopped on signal %s (%d)", task[i].name, SigName[rc], rc); Syslog('+', "Task %s is ready", task[i].name);
} else { } else if (WIFSIGNALED(task[i].status)) {
Syslog('+', "FIXME: 1"); rc = WTERMSIG(task[i].status);
} /*
break; * Here we don't report an error number, on FreeBSD WIFSIGNALED
} * seems true while there's nothing wrong.
*/
Syslog('+', "Task %s terminated", task[i].name);
} else if (WIFSTOPPED(task[i].status)) {
rc = WSTOPSIG(task[i].status);
Syslog('+', "Task %s stopped on signal %s (%d)", task[i].name, SigName[rc], rc);
} else {
Syslog('+', "FIXME: 1");
}
break;
}
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;