From 35f0336c12d77226f4856d3d04415fbfee93b233 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Wed, 10 Jul 2013 07:58:44 +0200 Subject: [PATCH] fix service level triggers Signed-off-by: John Crispin --- service.c | 12 ++++++++++-- trigger.c | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/service.c b/service.c index 8aae975..4189e2d 100644 --- a/service.c +++ b/service.c @@ -12,6 +12,7 @@ * GNU General Public License for more details. */ +#include #include #include "procd.h" #include "service.h" @@ -100,7 +101,13 @@ service_update(struct service *s, struct blob_attr *config, struct blob_attr **t struct blob_attr *cur; int rem; - s->trigger = tb[SERVICE_SET_TRIGGER]; + if (s->trigger) + trigger_del(s); + + if (tb[SERVICE_SET_TRIGGER] && blobmsg_data_len(tb[SERVICE_SET_TRIGGER])) { + s->trigger = tb[SERVICE_SET_TRIGGER]; + trigger_add(s->trigger, s); + } if (tb[SERVICE_SET_INSTANCES]) { if (!add) @@ -120,6 +127,7 @@ service_delete(struct service *s) { vlist_flush_all(&s->instances); avl_delete(&services, &s->avl); + trigger_del(s); free(s->config); free(s); } @@ -216,9 +224,9 @@ service_dump(struct service *s, int verbose) return; c = blobmsg_open_table(&b, s->name); - i = blobmsg_open_table(&b, "instances"); if (verbose && s->trigger) blobmsg_add_blob(&b, s->trigger); + i = blobmsg_open_table(&b, "instances"); vlist_for_each_element(&s->instances, in, node) instance_dump(&b, in, verbose); blobmsg_close_table(&b, i); diff --git a/trigger.c b/trigger.c index cecc6a6..d14101e 100644 --- a/trigger.c +++ b/trigger.c @@ -84,7 +84,7 @@ static void q_job_run(struct runqueue *q, struct runqueue_task *t) { struct job *j = container_of(t, struct job, proc.task); - LOG("handle event %s\n", j->cmd->name); + DEBUG(2, "handle event %s\n", j->cmd->name); j->cmd->handler(j, j->exec, j->env); } -- 2.25.1