SD_BUS_MESSAGE_READ_STRV(3)
π SD_BUS_MESSAGE_READ_STRV β bestie's guide to strv reading
okay so this whole page lives in the sd-bus manual family (that's the (3) part, iykyk), and it's all about two little functions that scoop an array of strings out of a D-Bus message. sound niche? it is. is it gonna slay your whole afternoon? maybe! let's go π
β¨ NAME β¨
sd_bus_message_read_strv, sd_bus_message_read_strv_extend β literally just here to give you access to an array of strings inside a message π
β¨ SYNOPSIS β¨
#include <systemd/sd-bus.h>
int sd_bus_message_read_strv(sd_bus_message *m, char ***l);
int sd_bus_message_read_strv_extend(sd_bus_message *m, char ***l);
πΈ DESCRIPTION πΈ
So sd_bus_message_read_strv() reads an array of string-like items out of the message m. the way that the "read pointer" in the message has to be sitting right before an array of strings (D-Bus type "as"), object paths (D-Bus type "ao"), or signatures (D-Bus type "ag"), okay? no skipping ahead bestie. on success, you get a pointer to a NULL-terminated array of strings (a strv) in the output parameter l. π¦
and here's the part where you gotta pay attention: ownership of this array is transferred to the caller. so that's on you now, bestie β you're responsible for freeing this array and its contents. main character responsibility, honestly. π
also, tiny optimization note (not me forgetting it, i would never): if an empty array is encountered, a NULL pointer might be returned here, and you should consider that equivalent to an array with zero entries. so don't panic when you see NULL, it's giving "empty, but make it fashion." π«Ά
sd_bus_message_read_strv_extend() is the sibling, and it's similar β but the second parameter is an input-output parameter. so:
- if
*lisNULL, it behaves identically tosd_bus_message_read_strv()(twins!) - otherwise,
*lmust point to a strv, and that strv will be reallocated and extended with additional strings β¨
this one is particularly useful when you're combining multiple lists of strings across a message or messages into a single array of strings. like gluing your playlists together. iconic behavior. π§
π₯ RETURN VALUE π₯
on success, these functions return a non-negative integer π on failure, they return a negative errno-style error code π
π Errors
the errors you might get back mean the following, so let's vibe check them one by one:
-EINVALβmorlareNULL. (you forgot something, bestie.)
Added in version 246.
-EPERMβ the message is not sealed. π (no seal, no deal.)
Added in version 246.
-EBADMSGβ the message cannot be parsed. (it's giving gibberish.)
Added in version 246.
-ENXIOβ the message "read pointer" is not right before an array of the appropriate type. (wrong spot, wrong vibe.)
Added in version 248.
π§ NOTES π§
the functions described here are available as a shared library, which you can compile against and link to with the libsystemd pkg-config(1) file. π
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. multiple independent objects may be used from different threads in parallel. so like, share the object, but not at the same time, okay? scheduling is everything. π
β οΈ okay this one matters: the code described here usesgetenv(3), which is declared to be not multi-thread-safe. that means the code calling the functions described here must not callsetenv(3)from a parallel thread. it's recommended to only do calls tosetenv()from an early phase of the program when no other threads have been started. early-phasesetenv()only, periodt. π
π HISTORY π
sd_bus_message_read_strv()was added in version 246.sd_bus_message_read_strv_extend()was added in version 252.
(so extend is the younger sibling, and honestly it ate. β)
π SEE ALSO π
systemd(1), sd-bus(3), sd_bus_message_read(3)
and that's the page, bestie! π this is from systemd 261.3, so if anyone asks, that's the version you're repping. go forth, read those strvs, free your memory, and don't call setenv() from a parallel thread β mwah πβ¨
π¦ 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