hotplug: send event notifications
authorFelix Fietkau <nbd@nbd.name>
Thu, 7 Aug 2025 11:27:05 +0000 (13:27 +0200)
committerFelix Fietkau <nbd@nbd.name>
Thu, 7 Aug 2025 13:44:21 +0000 (15:44 +0200)
Sent to per-subsystem ubus objects

Signed-off-by: Felix Fietkau <nbd@nbd.name>
hotplug-dispatch.c
plug/hotplug.c
procd.h

index 444e0a400de1df1a4df2032ffda6d5c5196836cf..6e999421a2194fe27367bf91ac249e4da04d8c7c 100644 (file)
@@ -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;
index 53f338339fdedf05ee82c21f795be21c93419458..432df5ecf2808d200fc3aedf767c6b938036f870 100644 (file)
@@ -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 bca3c42dfaeca614891243b3d8b5bcfa88968633..c656d3bb2cb9ee7fcce837c4623f832e4c12d689 100644 (file)
--- 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);