summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Fietkau2025-08-07 11:27:05 +0000
committerFelix Fietkau2025-08-07 13:44:21 +0000
commit4d023b8a8c510d5e8b4c616fb0ba4561d472587c (patch)
tree441d0aceff657dc7b1ea958d0d52a7ac0781ccba
parent84372dab89a860daaadea062fc93d99c1f14aa0c (diff)
downloadprocd-4d023b8a8c510d5e8b4c616fb0ba4561d472587c.tar.gz
hotplug: send event notifications
Sent to per-subsystem ubus objects Signed-off-by: Felix Fietkau <nbd@nbd.name>
-rw-r--r--hotplug-dispatch.c20
-rw-r--r--plug/hotplug.c6
-rw-r--r--procd.h7
3 files changed, 29 insertions, 4 deletions
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);