From: Felix Fietkau Date: Tue, 24 Jun 2014 20:34:50 +0000 (+0200) Subject: libubus: always defer processing incoming invoke/unsubscribe/notify if there is a... X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=bbd3fbc9cc914abfca9030253c0f2a68e1144c85;p=project%2Fubus.git libubus: always defer processing incoming invoke/unsubscribe/notify if there is a request pending This fixes recursion problems on config reload in netifd and simplifies application handling of requests Signed-off-by: Felix Fietkau --- diff --git a/libubus-internal.h b/libubus-internal.h index 6b40d7e..e4a5825 100644 --- a/libubus-internal.h +++ b/libubus-internal.h @@ -26,7 +26,6 @@ int __hidden ubus_start_request(struct ubus_context *ctx, struct ubus_request *r struct blob_attr *msg, int cmd, uint32_t peer); void ubus_process_obj_msg(struct ubus_context*ctx, struct ubus_msghdr *hdr); void ubus_process_req_msg(struct ubus_context *ctx, struct ubus_msghdr *hdr, int fd); -void ubus_process_pending_msg(struct ubus_context *ctx); void __hidden ubus_poll_data(struct ubus_context *ctx, int timeout); diff --git a/libubus-req.c b/libubus-req.c index cdb8393..7378a92 100644 --- a/libubus-req.c +++ b/libubus-req.c @@ -174,9 +174,6 @@ int ubus_complete_request(struct ubus_context *ctx, struct ubus_request *req, if (!registered) uloop_fd_delete(&ctx->sock); - if (!ctx->stack_depth) - ubus_process_pending_msg(ctx); - return status; } diff --git a/libubus.c b/libubus.c index 8683fcc..e852519 100644 --- a/libubus.c +++ b/libubus.c @@ -81,6 +81,7 @@ ubus_queue_msg(struct ubus_context *ctx, struct ubus_msghdr *hdr) memcpy(&pending->hdr, hdr, sizeof(*hdr) + blob_raw_len(ubus_msghdr_data(hdr))); list_add(&pending->list, &ctx->pending); + uloop_timeout_set(&ctx->pending_timer, 1); } void __hidden @@ -96,7 +97,7 @@ ubus_process_msg(struct ubus_context *ctx, struct ubus_msghdr *hdr, int fd) case UBUS_MSG_INVOKE: case UBUS_MSG_UNSUBSCRIBE: case UBUS_MSG_NOTIFY: - if (ctx->stack_depth > 2) { + if (ctx->stack_depth) { ubus_queue_msg(ctx, hdr); break; } @@ -106,17 +107,16 @@ ubus_process_msg(struct ubus_context *ctx, struct ubus_msghdr *hdr, int fd) } } -void __hidden ubus_process_pending_msg(struct ubus_context *ctx) +static void ubus_process_pending_msg(struct uloop_timeout *timeout) { + struct ubus_context *ctx = container_of(timeout, struct ubus_context, pending_timer); struct ubus_pending_msg *pending; - while (!list_empty(&ctx->pending)) { + while (!ctx->stack_depth && !list_empty(&ctx->pending)) { pending = list_first_entry(&ctx->pending, struct ubus_pending_msg, list); list_del(&pending->list); ubus_process_msg(ctx, &pending->hdr, -1); free(pending); - if (ctx->stack_depth > 2) - break; } } @@ -272,6 +272,7 @@ static int _ubus_connect(struct ubus_context *ctx, const char *path) ctx->sock.fd = -1; ctx->sock.cb = ubus_handle_data; ctx->connection_lost = ubus_default_connection_lost; + ctx->pending_timer.cb = ubus_process_pending_msg; INIT_LIST_HEAD(&ctx->requests); INIT_LIST_HEAD(&ctx->pending); diff --git a/libubus.h b/libubus.h index ad2db0c..6c560b4 100644 --- a/libubus.h +++ b/libubus.h @@ -140,6 +140,7 @@ struct ubus_context { struct list_head pending; struct uloop_fd sock; + struct uloop_timeout pending_timer; uint32_t local_id; uint16_t request_seq;