SD_BUS_ME...READ_ARRAY(3)
π sd_bus_message_read_array(3) β the manual page, bestie edition
okay so this is the page for sd_bus_message_read_array, from the sd_bus_message_read_array manual family (yes the header truncates it to SD_BUS_ME...READ_ARRAY(3), iconic abbreviation behaviour honestly). sit down, grab a strawberry drink π, and let's get into it.
β¨ NAME β¨
sd_bus_message_read_array β get your hands on an array of elements hanging out inside a message π«Ά
π SYNOPSIS π
#include <systemd/sd-bus.h>
int sd_bus_message_read_array(sd_bus_message *m, char type,
const void **ptr, size_t *size);
like, that's the whole vibe. three things in, one int out π
π¦ DESCRIPTION π¦
sd_bus_message_read_array() gives you access to an array of elements inside the bus message m. the "read pointer" in the message has to be right before an array of type type β like, it must be positioned exactly there, no skipping ahead π.
special case alert π¨: type may be NUL, and in that case any trivial type is acceptable. flexible queen behaviour.
a pointer to the array data comes back in the ptr parameter, and the size of the array data (in bytes, bytes bestie) comes back in the size parameter.
β οΈ if the returnedsizeparameter is0, a valid non-null pointer will still be returned asptrβ but you may not dereference it. it's giving decorative. look, don't touch π
the data is aligned as appropriate for the data type. the data is part of the message β so:
- it may not be modified π«
- it's only valid as long as the message is referenced β³
after this function returns, the "read pointer" points at the next element after the array. moving on up β¬οΈβ¨
π heads up: this function only supports arrays of trivial types β arrays of booleans, the various integer types, and floating point numbers. it may not be used for arrays of strings, structures or anything similar. so no string arrays, no struct arrays, none of that. don't even try it, i'm serious π
π₯ RETURN VALUE π₯
on success, and when an array was actually read, sd_bus_message_read_array() returns an integer greater than zero. slay β
if it's invoked while inside a container element (like an array β for example when you're operating on an array of arrays, yes that's a thing) and the final element of the outer container has already been read, so the read pointer is now behind the last element of the outer container β the call returns 0. and in that case the returned pointer will be NULL and the size will be 0. empty. void. nothing left. π«
on failure, it returns a negative errno-style error code. boo. π
πΈ Errors πΈ
the errors that can come back mean the following, respectively:
-EINVALβ the specifiedtypeis invalid or not a trivial type (see above π), or themessageparameter or one of the output parameters areNULL. basically something's missing or wrong-typed, check yourself bestie.-EOPNOTSUPPβ the byte order in the message is different than native byte order. not compatible, not today π ββοΈ-EPERMβ the message is not sealed. no seal, no deal π-EBADMSGβ the message cannot be parsed. it's corrupted, we can't read it, it's over π
π NOTES π
- the functions described here are available as a shared library, which you can compile against and link to with the
libsystemdpkg-config(1)file. standard icon behaviour π - all functions listed here are thread-agnostic, and only a single thread may operate on a given object at any given time. different threads may access the same object at different times, and multiple independent objects may be used from different threads in parallel. so like... share the object, but take turns. be polite β¨
- the code described here uses
getenv(3), which is declared to be not multi-thread-safe. this means that code calling the functions described here must not callsetenv(3)from a parallel thread. the recommendation is to only do calls tosetenv()from an early phase of the program, when no other threads have been started. front-load it, bestie, get it done before the party starts π§
β HISTORY β
sd_bus_message_read_array() was added in version 240. vintage but still iconic π
π SEE ALSO π
systemd(1), sd-bus(3), sd_bus_message_read(3), sd_bus_message_read_strv(3) β go read those too, iykyk π
and that's the page!! π«Ά brought to you by systemd 261.3 β mwah, love you, go read your arrays responsibly πβ¨π
π¦ where this page comes from
- ubuntu stonking: libsystemd-dev 261.3-0ubuntu3 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms