X-Git-Url: http://git.openwrt.org/?p=project%2Fprocd.git;a=blobdiff_plain;f=service%2Ftrigger.c;h=55d07e4dfa9b1611eb90b540befc32513d31656e;hp=ced758baefadf2ac2e6d2926512cc1aa24fd8665;hb=8eecf942b50d88dbcd7517817fe5c557f10541e0;hpb=386dfd4cdb444633861a812c645d56bd5c329c78 diff --git a/service/trigger.c b/service/trigger.c index ced758b..55d07e4 100644 --- a/service/trigger.c +++ b/service/trigger.c @@ -16,9 +16,6 @@ #include #include -#include -#include - #include #include #include @@ -65,7 +62,7 @@ struct job { }; static LIST_HEAD(triggers); -static struct runqueue q; +static RUNQUEUE(q, 1); static const char* rule_handle_var(struct json_script_ctx *ctx, const char *name, struct blob_attr *vars) { @@ -77,6 +74,9 @@ rule_load_script(struct json_script_ctx *ctx, const char *name) { struct trigger *t = container_of(ctx, struct trigger, jctx); + if (strcmp(name, t->type) != 0) + return NULL; + return json_script_file_from_blobmsg(t->type, t->rule, blob_pad_len(t->rule)); } @@ -217,15 +217,11 @@ static void rule_handle_error(struct json_script_ctx *ctx, const char *msg, free(s); } -static void q_empty(struct runqueue *q) -{ -} - static void trigger_delay_cb(struct uloop_timeout *tout) { struct trigger *t = container_of(tout, struct trigger, delay); - json_script_run(&t->jctx, "foo", t->data); + json_script_run(&t->jctx, t->type, t->data); free(t->data); t->data = NULL; } @@ -316,19 +312,12 @@ void trigger_del(void *id) } } -void trigger_init(void) -{ - runqueue_init(&q); - q.empty_cb = q_empty; - q.max_running_tasks = 1; -} - -static int trigger_match(const char *event, const char *match) +static bool trigger_match(const char *event, const char *match) { char *wildcard = strstr(match, ".*"); if (wildcard) - return strncmp(event, match, wildcard - match); - return strcmp(event, match); + return !strncmp(event, match, wildcard - match); + return !strcmp(event, match); } void trigger_event(const char *type, struct blob_attr *data) @@ -336,16 +325,16 @@ void trigger_event(const char *type, struct blob_attr *data) struct trigger *t; list_for_each_entry(t, &triggers, list) { - if (t->pending || t->remove) + if (t->remove) continue; - if (!trigger_match(type, t->type)) { - if (t->timeout) { - free(t->data); - t->data = blob_memdup(data); - uloop_timeout_set(&t->delay, t->timeout); - } else { - json_script_run(&t->jctx, "foo", data); - } + if (!trigger_match(type, t->type)) + continue; + if (t->timeout) { + free(t->data); + t->data = blob_memdup(data); + uloop_timeout_set(&t->delay, t->timeout); + } else { + json_script_run(&t->jctx, t->type, data); } } }