SD_BUS_ME...READ_BASIC(3)
π SD_BUS_MESSAGE_READ_BASIC(3) β sd_bus_message_read_basic π
okay bestie, sit down, because this one is a little gem from the sd-bus crew, and I promise it's not scary. it lives in the manual pages, section 3, and yes the title is hyphenated weirdly on purpose, iykyk π
β¨ NAME β¨
sd_bus_message_read_basic β literally just reads a basic type out of a message and moves on with its life π¦
β¨ SYNOPSIS β¨
#include <systemd/sd-bus.h>
int sd_bus_message_read_basic(sd_bus_message *m, char type, void *p);
that's it. that's the whole vibe. πΈ
β¨ DESCRIPTION β¨
so sd_bus_message_read_basic() reads a basic type from a message and advances the read position in the message. like, it grabs the thing at the cursor and then the cursor slides forward, no take-backs π
the set of basic types and their ascii codes that get passed in type are described in the D-Bus Specification (that's footnote [1] down at the bottom, don't worry, I got you π«Ά).
now the important bit, bestie, listen up β if p is not NULL, it should contain a pointer to an appropriate object. for example:
- if
typeis'y', the object passed inpshould have typeuint8_t * - if
typeis's', the object passed inpshould have typeconst char **
β οΈ borrowed, not yours to keep: if the basic type is a pointer (e.g., const char * in the case of a string), the pointer is only borrowed, and the contents must be copied if they are to be used after the end of the message's lifetime. similarly, during the lifetime of such a pointer, the message must not be modified. no cap, that one bites people π
and for 'h' (UNIX file descriptor): the descriptor is not duplicated by this call, and the returned descriptor remains in possession of the message object. so you need to duplicate it yourself if you want to keep an open reference after the message object is freed β for example by calling "fcntl(fd, FD_DUPFD_CLOEXEC, 3)". π (yes the manpage really has quotes around that, iconic honestly)
see the table below for a complete list of allowed types π
π Table 1. Item type specifiers π
"y"βSD_BUS_TYPE_BYTEβ 8-bit unsigned integer β expected C type:uint8_t *"b"βSD_BUS_TYPE_BOOLEANβ boolean β expected C type:int *(NB: notbool *) π"n"βSD_BUS_TYPE_INT16β 16-bit signed integer β expected C type:int16_t *"q"βSD_BUS_TYPE_UINT16β 16-bit unsigned integer β expected C type:uint16_t *"i"βSD_BUS_TYPE_INT32β 32-bit signed integer β expected C type:int32_t *"u"βSD_BUS_TYPE_UINT32β 32-bit unsigned integer β expected C type:uint32_t *"x"βSD_BUS_TYPE_INT64β 64-bit signed integer β expected C type:int64_t *"t"βSD_BUS_TYPE_UINT64β 64-bit unsigned integer β expected C type:uint64_t *"d"βSD_BUS_TYPE_DOUBLEβ IEEE 754 double precision floating-point β expected C type:double *"s"βSD_BUS_TYPE_STRINGβ UTF-8 string β expected C type:const char **"o"βSD_BUS_TYPE_OBJECT_PATHβ D-Bus object path string β expected C type:const char **"g"βSD_BUS_TYPE_SIGNATUREβ D-Bus signature string β expected C type:const char **"h"βSD_BUS_TYPE_UNIX_FDβ UNIX file descriptor β expected C type:int *
and if there is no object of the specified type at the current position in the message β boom, error returned. vibe check: failed π§
β¨ RETURN VALUE β¨
- on success,
sd_bus_message_read_basic()returns a positive integer β - if the end of the currently opened array has been reached, it returns 0 π
- on failure, it returns a negative errno-style error code π
πΈ Errors πΈ
returned errors may indicate the following problems:
-EINVALβ the specified type string is invalid, or the message parameter isNULL.-ENXIOβ the message does not contain the specified type at the current position.-EBADMSGβ the message cannot be parsed.
β¨ NOTES β¨
functions described here are available as a shared library, which can be compiled against and linked to with the libsystemd pkg-config(1) file. slay π«Ά
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. i.e. share the object, not the moment π
the code described here uses getenv(3), which is declared to be not multi-thread-safe. this means the code calling the functions described here must not call setenv(3) from a parallel thread. it's recommended to only do calls to setenv() from an early phase of the program when no other threads have been started. do your env setup first, party later π
β¨ HISTORY β¨
sd_bus_message_read_basic() was added in version 221. a true icon of its era π
β¨ SEE ALSO β¨
systemd(1), sd-bus(3), sd_bus_message_append_basic(3), sd_bus_message_skip(3), sd_bus_message_read(3)
β¨ NOTES (the footnote one) β¨
- D-Bus Specification β
https://dbus.freedesktop.org/doc/dbus-specification.htmlπ¦
and that's the whole page, bestie π sign-off time: this gorgeousness is from systemd 261.3, sitting pretty under the SD_BUS_ME...READ_BASIC(3) header. go read your messages. periodt. π
π¦ 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