Skip to content

!system/uorb: Return negated errno from uORB API on failure - #4025

Merged
xiaoxiang781216 merged 2 commits into
apache:masterfrom
Otpvondoiats:lk-uorb-1
Nov 14, 2026
Merged

xiaoxiang781216 merged 2 commits into
apache:masterfrom
Otpvondoiats:lk-uorb-1

Conversation

@Otpvondoiats

Copy link
Copy Markdown
Contributor

Note: Please adhere to Contributing Guidelines.

Summary

system/uorb: Fix uorb_unit_test not built with CMake. Kconfig defines UORB_TESTS and the Makefile checks CONFIG_UORB_TESTS, but CMakeLists.txt checked CONFIG_UORB_TEST, so uorb_unit_test was never built with CMake.

system/uorb: Return negated errno from uORB API on failure. The uORB API returned -1 and set errno on failure. It now returns a negated errno value, and the descriptions in uORB.h are updated.
orb_advsub_open() also returns the errno saved after SNIOC_REGISTER instead of the errno left by the following close().

Impact

uORB functions now return a negated errno value on failure instead of -1 with errno set. Callers that only test for a negative return value keep working. Callers that read errno after a failed call must use the returned value, e.g. replace
if (orb_copy(...) < 0) printf("%d", errno); with
ret = orb_copy(...); if (ret < 0) printf("%d", -ret);.

Testing

Host: Ubuntu Linux x86_64, GCC, CMake

nsh>uorb_listener -r 25 -n 25 sensor_mag0
Mointor objects num:1
object_name:sensor_mag, object_instance:0
sensor_mag(now:2865365051):timestamp:2707663615,x:-149.896393,y:-389.293884,z:-220.463440,temperature:0.000000,status:0
sensor_mag(now:2865489685):timestamp:2707703615,x:-150.230637,y:-389.202759,z:-219.237671,temperature:0.000000,status:0
sensor_mag(now:2865489990):timestamp:2707743615,x:-149.879517,y:-389.227142,z:-219.488007,temperature:0.000000,status:0
sensor_mag(now:2865491516):timestamp:2707783615,x:-149.779037,y:-389.239838,z:-219.347198,temperature:0.000000,status:0
sensor_mag(now:2865493041):timestamp:2707823615,x:-148.729019,y:-389.888672,z:-219.779419,temperature:0.000000,status:0
sensor_mag(now:2865494567):timestamp:2707863615,x:-149.073227,y:-389.185089,z:-220.190857,temperature:0.000000,status:0
sensor_mag(now:2865608581):timestamp:2707903615,x:-149.707916,y:-389.322723,z:-220.013535,temperature:0.000000,status:0
sensor_mag(now:2865608886):timestamp:2707943615,x:-149.779999,y:-389.199646,z:-220.833771,temperature:0.000000,status:0
sensor_mag(now:2865610412):timestamp:2707983615,x:-149.696411,y:-389.052399,z:-219.555817,temperature:0.000000,status:0
sensor_mag(now:2865730895):timestamp:2708023615,x:-149.845581,y:-389.792542,z:-219.673859,temperature:0.000000,status:0
sensor_mag(now:2865731201):timestamp:2708063615,x:-150.010117,y:-389.489929,z:-219.834244,temperature:0.000000,status:0
sensor_mag(now:2865852539):timestamp:2708103615,x:-149.796768,y:-389.511932,z:-219.720795,temperature:0.000000,status:0
sensor_mag(now:2865852844):timestamp:2708143615,x:-149.091064,y:-388.984955,z:-220.540329,temperature:0.000000,status:0
sensor_mag(now:2865854370):timestamp:2708183615,x:-149.085571,y:-389.660736,z:-220.046753,temperature:0.000000,status:0
sensor_mag(now:2865973632):timestamp:2708223615,x:-149.344223,y:-389.815857,z:-220.456238,temperature:0.000000,status:0
sensor_mag(now:2865973876):timestamp:2708263615,x:-149.703461,y:-389.259430,z:-218.869919,temperature:0.000000,status:0
sensor_mag(now:2866096862):timestamp:2708303615,x:-149.912354,y:-389.400848,z:-219.952255,temperature:0.000000,status:0
sensor_mag(now:2866097167):timestamp:2708343615,x:-149.551468,y:-389.319977,z:-220.629700,temperature:0.000000,status:0
sensor_mag(now:2866098693):timestamp:2708383615,x:-149.243759,y:-389.828583,z:-220.315430,temperature:0.000000,status:0
sensor_mag(now:2866100158):timestamp:2708423615,x:-149.555939,y:-389.156616,z:-219.660797,temperature:0.000000,status:0
sensor_mag(now:2866218444):timestamp:2708463615,x:-149.785263,y:-389.241547,z:-219.263077,temperature:0.000000,status:0
sensor_mag(now:2866218750):timestamp:2708503615,x:-149.597717,y:-389.230194,z:-220.299789,temperature:0.000000,status:0
sensor_mag(now:2866220275):timestamp:2708543615,x:-149.422485,y:-389.467834,z:-219.079865,temperature:0.000000,status:0
sensor_mag(now:2866221740):timestamp:2708583615,x:-149.643005,y:-389.407349,z:-220.595795,temperature:0.000000,status:0
sensor_mag(now:2866340148):timestamp:2708623615,x:-149.292709,y:-389.637054,z:-220.244339,temperature:0.000000,status:0
Object name:sensor_mag0, recieved:25
Total number of received Message:25/25

Kconfig defines the option as UORB_TESTS, but CMakeLists.txt checked
CONFIG_UORB_TEST, so uorb_unit_test was never built with CMake.

Use CONFIG_UORB_TESTS in CMakeLists.txt, matching Kconfig and the
Makefile.

Signed-off-by: v-chenglong8 <v-chenglong8@xiaomi.com>
The uORB API returned -1 and set errno on failure, so the error code
was only available through errno and had to be read right after the
call.

Make the uORB API return a negated errno value on failure and update
the function descriptions in uORB.h accordingly. orb_advsub_open() now
returns the errno saved after SNIOC_REGISTER instead of the errno left
by the following close().

BREAKING CHANGE: uORB functions (orb_open, orb_close, orb_advertise_*,
orb_subscribe_*, orb_publish_*, orb_copy_*, orb_ioctl, orb_flush,
orb_get_state, orb_get_events, orb_check, orb_exists,
orb_set_interval, orb_set_batch_interval, orb_get_info, ...) now return
a negated errno value on failure instead of -1 with errno set. Callers
that only test for a negative return value keep working. Callers that
read errno after a failed call must use the returned value instead,
e.g. replace "if (orb_copy(...) < 0) printf("%d", errno);" with
"ret = orb_copy(...); if (ret < 0) printf("%d", -ret);".

Signed-off-by: chenzihan1 <chenzihan1@xiaomi.com>
Signed-off-by: likun17 <likun17@xiaomi.com>
@xiaoxiang781216
xiaoxiang781216 merged commit 5b68053 into apache:master Nov 14, 2026
55 of 78 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants