From: Felix Fietkau Date: Thu, 7 Aug 2025 11:27:05 +0000 (+0200) Subject: hotplug: send event notifications X-Git-Url: http://git.openwrt.org/?a=commitdiff_plain;h=4d023b8a8c510d5e8b4c616fb0ba4561d472587c;p=project%2Fprocd.git hotplug: send event notifications Sent to per-subsystem ubus objects Signed-off-by: Felix Fietkau --- diff --git a/hotplug-dispatch.c b/hotplug-dispatch.c index 444e0a4..6e99942 100644 --- a/hotplug-dispatch.c +++ b/hotplug-dispatch.c @@ -445,6 +445,26 @@ static void inotify_read_handler(struct uloop_fd *u, unsigned int events) } } +void hotplug_ubus_event(struct blob_attr *data) +{ + static const struct blobmsg_policy policy = + { "SUBSYSTEM", BLOBMSG_TYPE_STRING }; + struct hotplug_subsys *h; + struct blob_attr *attr; + const char *subsys; + + blobmsg_parse_attr(&policy, 1, &attr, data); + if (!attr) + return; + + subsys = blobmsg_get_string(attr); + h = avl_find_element(&subsystems, subsys, h, node); + if (!h) + return; + + ubus_notify(ctx, &h->ubus, "event", data, -1); +} + void ubus_init_hotplug(struct ubus_context *newctx) { ctx = newctx; diff --git a/plug/hotplug.c b/plug/hotplug.c index 53f3383..432df5e 100644 --- a/plug/hotplug.c +++ b/plug/hotplug.c @@ -569,14 +569,12 @@ static void hotplug_handler(struct uloop_fd *u, unsigned int ev) int i = 0; static char buf[4096]; int len = recv(u->fd, buf, sizeof(buf) - 1, MSG_DONTWAIT); - void *index; if (len < 1) return; buf[len] = '\0'; blob_buf_init(&b, 0); - index = blobmsg_open_table(&b, NULL); while (i < len) { int l = strlen(buf + i) + 1; char *e = strstr(&buf[i], "="); @@ -587,9 +585,9 @@ static void hotplug_handler(struct uloop_fd *u, unsigned int ev) } i += l; } - blobmsg_close_table(&b, index); + hotplug_ubus_event(b.head); hotplug_handler_debug(b.head); - json_script_run(&jctx, rule_file, blob_data(b.head)); + json_script_run(&jctx, rule_file, b.head); } static struct uloop_fd hotplug_fd = { diff --git a/procd.h b/procd.h index bca3c42..c656d3b 100644 --- a/procd.h +++ b/procd.h @@ -34,6 +34,13 @@ void procd_reconnect_ubus(int reconnect); void ubus_init_hotplug(struct ubus_context *ctx); void ubus_init_service(struct ubus_context *ctx); void ubus_init_system(struct ubus_context *ctx); +#ifndef DISABLE_INIT +void hotplug_ubus_event(struct blob_attr *data); +#else +static inline void hotplug_ubus_event(struct blob_attr *data) +{ +} +#endif void procd_state_next(void); void procd_state_ubus_connect(void);