openwrt / openwrt

This repository is a mirror of https://git.openwrt.org/openwrt/openwrt.git It is for reference only and is not active for check-ins. We will continue to accept Pull Requests here. They will be merged via staging trees then into openwrt.git.
Other
19.12k stars 10.08k forks source link

The ubus object exists, but when called by invoke, it returns the status 4 #15625

Open zhengyikeng opened 1 month ago

zhengyikeng commented 1 month ago

Describe the bug

I added an Ubus object, which can be queried through the Ubus list

root@DataJar-D0F1:~# ubus -v list systemd.virtual_led_service
'systemd.virtual_led_service' @44c1359e
        "list":{}
        "set":{"led_name":"String","led_status":"Integer"}
        "get":{"led_name":"String"}

The ubus object exists, but when called by invoke, it returns the status 4.

ubus call systemd.virtual_led_service list &
-> b2b0087d #b2b0087d          hello: {}
<- b2b0087d #00000000         lookup: {"objpath":"systemd.virtual_led_service"}
-> b2b0087d #00000000           data: {"objpath":"systemd.virtual_led_service","objid":1153512862,"objtype":-290628632,"signature":{"list":{},"set":{"led_name":3,"led_status":5},"get":{"led_name":3}}}
-> b2b0087d #00000000         status: {"status":0}
<- b2b0087d #44c1359e         invoke: {"objid":1153512862,"method":"list","data":{}}
-> 808599b2 #b2b0087d         invoke: {"objid":1153512862,"method":"list","data":{},"user":"root","group":"root"}
<- 808599b2 #00000000         status: {"status":4,"objid":0}

Status 4 means UBUS_STATUS_NOT_FOUND? May I ask how to troubleshoot?

OpenWrt version

DISTRIB_REVISION='2.14.51'

OpenWrt release

DISTRIB_RELEASE='22.03.3'

OpenWrt target/subtarget

DISTRIB_TARGET='rockchip/armv8'

Device

RK3308B

Image kind

Self-built image

Steps to reproduce

No response

Actual behaviour

No response

Expected behaviour

No response

Additional info

No response

Diffconfig

No response

Terms

github-actions[bot] commented 1 month ago

Invalid Version reported. DISTRIB_REVISION='2.14.51' Is this from a clean repository?

github-actions[bot] commented 1 month ago

Invalid Release reported. DISTRIB_RELEASE='22.03.3' Is this from a clean repository?

github-actions[bot] commented 1 month ago

Invalid Target/Subtarget reported. DISTRIB_TARGET='rockchip/armv8' Is this from a supported device?

brada4 commented 1 month ago

Can you repeat on mainstream stable OpenWRT and copy proper release tags?

zhengyikeng commented 1 month ago

My problem has been resolved. My code has a mechanism that attempts to subscribe periodically after a subscription failure. The same struct ubus_subscriber has called API ubus_register_subscriber() multiple times, which can cause structural abnormalities in the avl tree

image

Just a suggestion, would it be better to do a check before insertion

diff --git a/libubus-obj.c b/libubus-obj.c
index 29cbb2b..aec0a4d 100644
--- a/libubus-obj.c
+++ b/libubus-obj.c
@@ -169,7 +169,9 @@ static void ubus_add_object_cb(struct ubus_request *req, int type, struct blob_a

        if (attrbuf[UBUS_ATTR_OBJTYPE])
                obj->type->id = blob_get_u32(attrbuf[UBUS_ATTR_OBJTYPE]);
-
+       /*
+        * Suggest: check if avl node exists in the AVL tree? and if it exists, would it be better to remove it first?
+        */
        obj->avl.key = &obj->id;
        avl_insert(&req->ctx->objects, &obj->avl);