static void __runqueue_task_timeout(struct uloop_timeout *timeout) { struct runqueue_task *t = container_of(timeout, struct runqueue_task, timeout); if (t->cancelled) runqueue_task_kill(t); else runqueue_task_cancel(t, t->cancel_type); }
/* called by main to request scripts to be run */ void scripts_run(struct ping_intf* pi, enum online_state state_new) { struct scripts_proc* scr; struct scripts_proc* scr_other; const char* state_str; if (state_new == ONLINE) { scr = &pi->scripts_on; scr_other = &pi->scripts_off; state_str = "online"; } else { scr = &pi->scripts_off; scr_other = &pi->scripts_on; state_str = "offline"; } /* * cancel obsolete other task: e.g when ONLINE script is getting queued * and OFFLINE script is already queued and not running yet, cancel it */ if (scr_other->proc.task.queued && !scr_other->proc.task.running) { printlog(LOG_NOTICE, "Cancelling obsolete '%s' scripts for '%s'", scr->state != ONLINE ? "online" : "offline", pi->name); runqueue_task_cancel(&scr_other->proc.task, 1); } /* don't queue the same scripts twice */ if (scr->proc.task.queued || scr->proc.task.running) { printlog(LOG_NOTICE, "'%s' scripts for '%s' already queued or running", state_str, pi->name); return; } /* add runqueue task for running the scripts */ printlog(LOG_NOTICE, "Scheduling '%s' scripts for '%s'", state_str, pi->name); scr->proc.task.type = &task_scripts_type; scr->proc.task.run_timeout = SCRIPTS_TIMEOUT * 1000; scr->intf = pi; scr->state = state_new; runqueue_task_add(&runq, &scr->proc.task, false); }