Skip to content
Open
30 changes: 23 additions & 7 deletions src/runner.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ schedule_exec(struct lmapd *lmapd, struct schedule *schedule)

// lmap_dbg("executing schedule '%s'", schedule->name);

/* avoid leftover data (possibly due to a crash) from
* previous runs of an action. */
for (act = schedule->actions; act; act = act->next) {
(void) lmapd_workspace_action_clean(lmapd, act);
}

event_base_gettimeofday_cached(lmapd->base, &t);

switch (schedule->mode) {
Expand Down Expand Up @@ -528,7 +534,7 @@ void
lmapd_cleanup(struct lmapd *lmapd)
{
pid_t pid;
int status, failed;
int status, failed, succeeded;
struct lmap *lmap;
struct timeval t;
struct action *action;
Expand Down Expand Up @@ -619,25 +625,34 @@ lmapd_cleanup(struct lmapd *lmapd)

/*
* Change schedule state back to enabled if all actions have
* left the running state.
* left the running state. If at least one action was executed
* and every action returned success, clean up the schedule
* input processing queue.
*/

if (schedule->state == LMAP_SCHEDULE_STATE_RUNNING) {
schedule->state = LMAP_SCHEDULE_STATE_ENABLED;
if (schedule->cnt_active_suppressions) {
schedule->state = LMAP_SCHEDULE_STATE_SUPPRESSED;
}
failed = 0;
succeeded = failed = 0;
for (action = schedule->actions; action; action = action->next) {
if (action->state == LMAP_ACTION_STATE_RUNNING) {
schedule->state = LMAP_SCHEDULE_STATE_RUNNING;
}
if (action->last_status) {
failed++;
failed = 1;
} else {
succeeded = 1;
}
}
if (schedule->state != LMAP_SCHEDULE_STATE_RUNNING && failed) {
schedule->cnt_failures++;
if (schedule->state != LMAP_SCHEDULE_STATE_RUNNING) {
if (failed) {
schedule->cnt_failures++;
} else if (succeeded) {
/* there was at least one action, and none failed */
lmapd_workspace_schedule_clean(lmapd, schedule);
}
}
}
}
Expand Down Expand Up @@ -694,7 +709,8 @@ execute_cb(struct lmapd *lmapd, struct event *event)
event_base_gettimeofday_cached(lmapd->base, &t);
sched->cycle_number = (t.tv_sec / event->cycle_interval) * event->cycle_interval;
}


lmapd_workspace_schedule_move(lmapd, sched);
schedule_exec(lmapd, sched);
if (event->type == LMAP_EVENT_TYPE_ONE_OFF
|| event->type == LMAP_EVENT_TYPE_IMMEDIATE
Expand Down
Loading