fix service level triggers
authorJohn Crispin <blogic@openwrt.org>
Wed, 10 Jul 2013 05:58:44 +0000 (07:58 +0200)
committerJohn Crispin <blogic@openwrt.org>
Wed, 10 Jul 2013 10:49:02 +0000 (12:49 +0200)
Signed-off-by: John Crispin <blogic@openwrt.org>
service.c
trigger.c

index 8aae975cc4cb5f3354c2ab384371dd3f6f7bc5ff..4189e2d4b8e79fc3bce29bc1db5396a2065bf906 100644 (file)
--- a/service.c
+++ b/service.c
@@ -12,6 +12,7 @@
  * GNU General Public License for more details.
  */
 
+#include <libubox/blobmsg_json.h>
 #include <libubox/avl-cmp.h>
 #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);
index cecc6a6b72bd16a22e00248935912fe66046073c..d14101ea18e332f8ca7418c941ccdf4e3633644c 100644 (file)
--- 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);
 }