[PATCH 1/5] procd: add restart ubus call

Florian Eckert fe at dev.tdt.de
Wed Dec 2 09:52:29 EST 2020


To allow other services to respsond to a restart event from a procd initialised
service, a new ubus method "restart" in the ubus "service" path is needed
to trigger a ubus notify and also execute the installed service triggers.

Cc: Aaron Goodman <aaronjg at alumni.stanford.edu>
Signed-off-by: Florian Eckert <fe at dev.tdt.de>
The original implementation is by Aaron Goodman.
---
 .../patches/0010-add-restart-event.patch      | 64 +++++++++++++++++++
 1 file changed, 64 insertions(+)
 create mode 100644 package/system/procd/patches/0010-add-restart-event.patch

diff --git a/package/system/procd/patches/0010-add-restart-event.patch b/package/system/procd/patches/0010-add-restart-event.patch
new file mode 100644
index 0000000000..86ec3d38e1
--- /dev/null
+++ b/package/system/procd/patches/0010-add-restart-event.patch
@@ -0,0 +1,64 @@
+--- a/service/service.c
++++ b/service/service.c
+@@ -204,6 +204,17 @@ static const struct blobmsg_policy servi
+ };
+ 
+ enum {
++	SERVICE_RESTART_ATTR_NAME,
++	SERVICE_RESTART_ATTR_INSTANCE,
++	__SERVICE_RESTART_ATTR_MAX,
++};
++
++static const struct blobmsg_policy service_restart_attrs[__SERVICE_RESTART_ATTR_MAX] = {
++	[SERVICE_RESTART_ATTR_NAME] = { "name", BLOBMSG_TYPE_STRING },
++	[SERVICE_RESTART_ATTR_INSTANCE] = { "instance", BLOBMSG_TYPE_STRING },
++};
++
++enum {
+ 	SERVICE_DEL_ATTR_NAME,
+ 	SERVICE_DEL_ATTR_INSTANCE,
+ 	__SERVICE_DEL_ATTR_MAX,
+@@ -681,6 +692,35 @@ service_handle_update(struct ubus_contex
+ 	return 0;
+ }
+ 
++static int
++service_handle_restart(struct ubus_context *ctx, struct ubus_object *obj,
++		       struct ubus_request_data *req, const char *method,
++		       struct blob_attr *msg)
++{
++	struct blob_attr *tb[__SERVICE_RESTART_ATTR_MAX], *cur;
++	struct service *s = NULL;
++	const char *name;
++
++	blobmsg_parse(service_set_attrs, __SERVICE_RESTART_ATTR_MAX, tb, blobmsg_data(msg), blobmsg_data_len(msg));
++	cur = tb[SERVICE_RESTART_ATTR_NAME];
++	if (!cur)
++		return UBUS_STATUS_INVALID_ARGUMENT;
++
++	name = blobmsg_data(cur);
++
++	s = avl_find_element(&services, name, s, avl);
++	if (!s)
++		return UBUS_STATUS_INVALID_ARGUMENT;
++
++	blob_buf_init(&b, 0);
++	blobmsg_add_string(&b, "service", s->name);
++	trigger_event("service.restart", b.head);
++
++	service_event("service.restart", s->name, NULL);
++
++	return UBUS_STATUS_OK;
++}
++
+ static void ubus_event_bcast(const char *type, const char *param1, const char *val1,
+ 			     const char *param2, const char *val2)
+ {
+@@ -951,6 +991,7 @@ static struct ubus_method main_object_me
+ 	UBUS_METHOD("add", service_handle_set, service_set_attrs),
+ 	UBUS_METHOD("list", service_handle_list, service_list_attrs),
+ 	UBUS_METHOD("delete", service_handle_delete, service_del_attrs),
++	UBUS_METHOD("restart", service_handle_restart, service_restart_attrs),
+ 	UBUS_METHOD("signal", service_handle_signal, service_signal_attrs),
+ 	UBUS_METHOD("update_start", service_handle_update, service_attrs),
+ 	UBUS_METHOD("update_complete", service_handle_update, service_attrs),
-- 
2.20.1




More information about the openwrt-devel mailing list