diff options
| author | Felix Fietkau | 2023-11-28 12:14:45 +0000 |
|---|---|---|
| committer | Felix Fietkau | 2023-11-28 12:17:43 +0000 |
| commit | 2b39a27d8bcc98859a67a9a925c77ecde6b1e698 (patch) | |
| tree | 7ba2596b6a942bedfcb888f2cc09b10adbc59366 | |
| parent | b3e8c4ef07ebb6f0f34a5c1f0dc1539068363619 (diff) | |
libubus: fix reconnect with auto subscribe
Look up all objects after reconnect and re-subscribe
Signed-off-by: Felix Fietkau <nbd@nbd.name>
| -rw-r--r-- | libubus-io.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/libubus-io.c b/libubus-io.c index a1fb62b..d190b67 100644 --- a/libubus-io.c +++ b/libubus-io.c @@ -345,6 +345,29 @@ void __hidden ubus_poll_data(struct ubus_context *ctx, int timeout) } static void +ubus_auto_sub_lookup(struct ubus_context *ctx, struct ubus_object_data *obj, + void *priv) +{ + struct ubus_subscriber *s; + + list_for_each_entry(s, &ctx->auto_subscribers, list) + if (s->new_obj_cb(ctx, s, obj->path)) + ubus_subscribe(ctx, s, obj->id); +} + +static void +ubus_refresh_auto_subscribe(struct ubus_context *ctx) +{ + struct ubus_event_handler *ev = &ctx->auto_subscribe_event_handler; + + if (list_empty(&ctx->auto_subscribers)) + return; + + ubus_register_event_handler(ctx, ev, "ubus.object.add"); + ubus_lookup(ctx, NULL, ubus_auto_sub_lookup, NULL); +} + +static void ubus_refresh_state(struct ubus_context *ctx) { struct ubus_object *obj, *tmp; @@ -365,6 +388,8 @@ ubus_refresh_state(struct ubus_context *ctx) for (n = i, i = 0; i < n; i++) ubus_add_object(ctx, objs[i]); + + ubus_refresh_auto_subscribe(ctx); } int ubus_reconnect(struct ubus_context *ctx, const char *path) |