trigger: replace trigger_init() with static runqueue initialization
[project/procd.git] / service / trigger.c
index 216e1f2f00f7191e700f24c7612a3517e30b1f94..55d07e4dfa9b1611eb90b540befc32513d31656e 100644 (file)
@@ -62,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)
 {
@@ -217,10 +217,6 @@ 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);
@@ -316,13 +312,6 @@ void trigger_del(void *id)
        }
 }
 
-void trigger_init(void)
-{
-       runqueue_init(&q);
-       q.empty_cb = q_empty;
-       q.max_running_tasks = 1;
-}
-
 static bool trigger_match(const char *event, const char *match)
 {
        char *wildcard = strstr(match, ".*");
@@ -338,14 +327,14 @@ void trigger_event(const char *type, struct blob_attr *data)
        list_for_each_entry(t, &triggers, list) {
                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, t->type, 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);
                }
        }
 }