static void add_initd(struct runqueue *q, char *file, char *param) { static const struct runqueue_task_type initd_type = { .run = q_initd_run, .cancel = runqueue_process_cancel_cb, .kill = runqueue_process_kill_cb, }; struct initd *s; char *p, *f; s = calloc_a(sizeof(*s), &f, strlen(file) + 1, &p, strlen(param) + 1); if (!s) { ERROR("Out of memory in %s.\n", file); return; } s->proc.task.type = &initd_type; s->proc.task.complete = q_initd_complete; if (!strcmp(param, "stop") || !strcmp(param, "shutdown")) s->proc.task.run_timeout = 15000; s->param = p; s->file = f; strcpy(s->param, param); strcpy(s->file, file); runqueue_task_add(q, &s->proc.task, false); }
void runqueue_process_add(struct runqueue *q, struct runqueue_process *p, pid_t pid) { if (p->proc.pending) return; p->proc.pid = pid; p->proc.cb = __runqueue_proc_cb; if (!p->task.type) p->task.type = &runqueue_proc_type; uloop_process_add(&p->proc); if (!p->task.running) runqueue_task_add(q, &p->task, true); }
/* 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); }