diff options
author | Felix Fietkau <nbd@nbd.name> | 2025-03-07 14:33:10 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2025-03-16 23:58:45 +0100 |
commit | fb1da7157d138adcc4e20d41685aa6ab400bc042 (patch) | |
tree | 6cf171efb1ee4010223e1ccd87a9422d0d69c318 | |
parent | 0002684b9772ad9bb0a62e498d3556573d15b819 (diff) |
ubus: remove broken implied await when calling defer() outside of uloop.run()
Calling ubus.defer() outside of uloop.run() was apparently broken since commit
1cb04f9b76e2 ("ubus: add object publishing, notify and subscribe support") from
March 2022.
It was supposed to block until the request completes, however it blocked forever
due to a counter imbalance introduced by the above commit.
These days this 'feature' is of questionable value, since req.await() exists,
and there is a legitimate use for issuing deferred requests from outside of
uloop.run() and then calling uloop.run() or req.await() afterwards.
Since nobody noticed the breakage in all this time, let's just get rid of
this API footgun.
Signed-off-by: Felix Fietkau <nbd@nbd.name>
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | lib/ubus.c | 36 |
2 files changed, 0 insertions, 37 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b7e412..d7e7006 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -180,7 +180,6 @@ if(UBUS_SUPPORT) try_compile(HAVE_NEW_UBUS_STATUS_CODES ${CMAKE_BINARY_DIR} "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/test.c") - check_symbol_exists(uloop_fd_set_cb "libubox/uloop.h" FD_SET_CB_EXISTS) check_function_exists(uloop_timeout_remaining64 REMAINING64_FUNCTION_EXISTS) check_function_exists(ubus_channel_connect HAVE_CHANNEL_SUPPORT) if(REMAINING64_FUNCTION_EXISTS) @@ -134,9 +134,6 @@ static uc_resource_type_t *defer_type; static uc_resource_type_t *conn_type; static uc_resource_type_t *chan_type; -static uint64_t n_cb_active; -static bool have_own_uloop; - static struct blob_buf buf; typedef struct { @@ -651,11 +648,6 @@ uc_ubus_call_user_cb(uc_ubus_deferred_t *defer, int ret, uc_value_t *reply) } request_reg_clear(defer->vm, defer->registry_index); - - n_cb_active--; - - if (have_own_uloop && n_cb_active == 0) - uloop_end(); } static void @@ -740,24 +732,6 @@ uc_ubus_call_timeout_cb(struct uloop_timeout *timeout) uc_ubus_call_user_cb(defer, UBUS_STATUS_TIMEOUT, NULL); } -static bool -uc_ubus_have_uloop(void) -{ - bool prev = uloop_cancelled; - bool active; - -#ifdef HAVE_ULOOP_FD_SET_CB - if (uloop_fd_set_cb) - return true; -#endif - - uloop_cancelled = true; - active = uloop_cancelling(); - uloop_cancelled = prev; - - return active; -} - static int get_fd(uc_vm_t *vm, uc_value_t *val) { @@ -1000,11 +974,6 @@ uc_ubus_defer_common(uc_vm_t *vm, uc_ubus_connection_t *c, uc_ubus_call_res_t *r defer->registry_index = request_reg_add(vm, ucv_get(res->res), ucv_get(replycb), ucv_get(datacb), ucv_get(fdcb), ucv_get(conn), ucv_get(fd)); - - if (!uc_ubus_have_uloop()) { - have_own_uloop = true; - uloop_run(); - } } else { uc_vm_stack_push(vm, ucv_get(replycb)); @@ -2347,11 +2316,6 @@ uc_ubus_defer_abort(uc_vm_t *vm, size_t nargs) request_reg_clear((*d)->vm, (*d)->registry_index); - n_cb_active--; - - if (have_own_uloop && n_cb_active == 0) - uloop_end(); - (*d)->complete = true; ok_return(ucv_boolean_new(true)); |