summaryrefslogtreecommitdiffstats
path: root/service/service.c
diff options
context:
space:
mode:
authorJohn Crispin <blogic@openwrt.org>2014-06-04 21:50:00 +0200
committerJohn Crispin <blogic@openwrt.org>2014-06-05 12:45:15 +0200
commit1fd4e60e9d03c0e3aa79f5f0bac87f07c63081f5 (patch)
treeed6698f6ed6a10e4aa5d4c0f2a04e51a2a056441 /service/service.c
parent386dfd4cdb444633861a812c645d56bd5c329c78 (diff)
downloadunitd-1fd4e60e9d03c0e3aa79f5f0bac87f07c63081f5.tar
unitd-1fd4e60e9d03c0e3aa79f5f0bac87f07c63081f5.zip
send ubus_notify events when servers and instances change state
Signed-off-by: John Crispin <blogic@openwrt.org>
Diffstat (limited to 'service/service.c')
-rw-r--r--service/service.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/service/service.c b/service/service.c
index 8d1217f..6426929 100644
--- a/service/service.c
+++ b/service/service.c
@@ -24,6 +24,7 @@
struct avl_tree services;
static struct blob_buf b;
+static struct ubus_context *ctx;
static void
service_instance_add(struct service *s, struct blob_attr *attr)
@@ -146,6 +147,7 @@ service_update(struct service *s, struct blob_attr **tb, bool add)
static void
service_delete(struct service *s)
{
+ service_event("service.stop", s->name, NULL);
vlist_flush_all(&s->instances);
avl_delete(&services, &s->avl);
trigger_del(s);
@@ -242,6 +244,8 @@ service_handle_set(struct ubus_context *ctx, struct ubus_object *obj,
avl_insert(&services, &s->avl);
+ service_event("service.start", s->name, NULL);
+
return 0;
}
@@ -447,8 +451,18 @@ service_start_early(char *name, char *cmdline)
return service_handle_set(NULL, NULL, NULL, "add", b.head);
}
-void ubus_init_service(struct ubus_context *ctx)
+void service_event(const char *type, const char *service, const char *instance)
+{
+ blob_buf_init(&b, 0);
+ blobmsg_add_string(&b, "service", service);
+ if (instance)
+ blobmsg_add_string(&b, "instance", instance);
+ ubus_notify(ctx, &main_object, type, b.head, -1);
+}
+
+void ubus_init_service(struct ubus_context *_ctx)
{
+ ctx = _ctx;
ubus_add_object(ctx, &main_object);
}