diff options
| author | Felix Fietkau | 2023-11-28 12:23:38 +0000 |
|---|---|---|
| committer | Felix Fietkau | 2023-11-28 12:24:00 +0000 |
| commit | d49aadabb7a147b99a3e6299a77d7fda4e266091 (patch) | |
| tree | 3f457c991d44765334994d5acd5a544f89cf6fc9 | |
| parent | d4b99820afd03a726ea50687d4393007da0fd0df (diff) | |
| download | udebug-d49aadabb7a147b99a3e6299a77d7fda4e266091.tar.gz | |
lib: fix dealing with udebugd restarts
When re-subscribing, also re-request the configuration in order to
avoid using stale data
Signed-off-by: Felix Fietkau <nbd@nbd.name>
| -rw-r--r-- | lib.c | 28 | ||||
| -rw-r--r-- | udebug.h | 1 |
2 files changed, 21 insertions, 8 deletions
@@ -52,14 +52,29 @@ static bool udebug_ubus_new_obj_cb(struct ubus_context *ubus, struct ubus_subscriber *sub, const char *path) { - return !strcmp(path, "udebug"); + struct udebug_ubus *ctx = container_of(sub, struct udebug_ubus, sub); + + if (strcmp(path, "udebug") != 0) + return false; + + uloop_timeout_set(&ctx->t, 1); + return true; } -void udebug_ubus_init(struct udebug_ubus *ctx, struct ubus_context *ubus, - const char *service, udebug_config_cb cb) +static void udebug_ubus_get_config(struct uloop_timeout *t) { + struct udebug_ubus *ctx = container_of(t, struct udebug_ubus, t); uint32_t id; + if (ubus_lookup_id(ctx->ubus, "udebug", &id)) + return; + + ubus_invoke(ctx->ubus, id, "get_config", NULL, udebug_ubus_req_cb, ctx, 1000); +} + +void udebug_ubus_init(struct udebug_ubus *ctx, struct ubus_context *ubus, + const char *service, udebug_config_cb cb) +{ ctx->ubus = ubus; ctx->service = service; ctx->cb = cb; @@ -67,11 +82,7 @@ void udebug_ubus_init(struct udebug_ubus *ctx, struct ubus_context *ubus, ctx->sub.cb = udebug_ubus_notify_cb; ubus_register_subscriber(ubus, &ctx->sub); - if (ubus_lookup_id(ubus, "udebug", &id)) - return; - - ubus_subscribe(ubus, &ctx->sub, id); - ubus_invoke(ubus, id, "get_config", NULL, udebug_ubus_req_cb, ctx, 1000); + ctx->t.cb = udebug_ubus_get_config; } void udebug_ubus_free(struct udebug_ubus *ctx) @@ -79,5 +90,6 @@ void udebug_ubus_free(struct udebug_ubus *ctx) if (!ctx->ubus) return; + uloop_timeout_cancel(&ctx->t); ubus_unregister_subscriber(ctx->ubus, &ctx->sub); } @@ -6,6 +6,7 @@ typedef void (*udebug_config_cb)(struct udebug_ubus *ctx, struct blob_attr *data struct udebug_ubus { struct ubus_context *ubus; + struct uloop_timeout t; const char *service; struct ubus_subscriber sub; udebug_config_cb cb; |