SD_BUS_MESSAGE_DUMP(3)
π SD_BUS_MESSAGE_DUMP(3) π
hi bestie!! welcome to the sd_bus_message_dump page (that's the manual name right there, SD_BUS_MESSAGE_DUMP(3), iykyk) β it's all about turning a D-Bus message into something you can actually look at when you're debugging. no cap, it's giving "print it and stare at it" energy. π
β¨ NAME β¨
sd_bus_message_dump, sd_bus_message_dump_json β produce a string representation of a message for debugging purposes
like, that's the whole vibe: you got a message, you wanna see it. π¦
π«Ά SYNOPSIS π«Ά
#include <systemd/sd-bus.h>
int sd_bus_message_dump(sd_bus_message *m, FILE *f, uint64_t flags);
int sd_bus_message_dump_json(sd_bus_message *m, uint64_t flags,
sd_json_variant **ret);
πΈ DESCRIPTION πΈ
okay so first up, sd_bus_message_dump() β it writes a textual representation of the message m into the stream f. and if f is NULL? it just uses standard output (stdio), iconic behavior honestly. π
heads up bestie: this function is for debugging purposes only. the output is neither stable nor designed to be machine readable. do not parse it. do not build your whole pipeline on it. it's a vibe, not a contract. π
then there's sd_bus_message_dump_json() β this one converts the D-Bus message m to a JSON variant and stashes it in ret. you, the caller, are responsible for calling sd_json_variant_unref() on that JSON variant once you're done with it (yes, clean up after yourself, we love a responsible queen π). and unlike sd_bus_message_dump(), this function doesn't print anything itself. so if you want the D-Bus message printed in JSON format, you pass the returned JSON variant to sd_json_variant_dump(). that's the whole recipe. π
the flags parameter is how you tweak the output β it's a combination of zero or more of these bad boys:
SD_BUS_MESSAGE_DUMP_WITH_HEADERβ the header of the message, which specifies the message type, flags, and several more additional metadata, gets printed (or included in the resulting JSON object). main character energy for your metadata fr fr β¨SD_BUS_MESSAGE_DUMP_SUBTREE_ONLYβ only the current container gets printed or converted. leave this flag off and the contents of the whole entire message get printed or converted. so like, do you want the whole tree or just this branch? your call. π³
IMPORTANT: these functions move the read pointer of the message. so you might need to reset the position afterwards, for example with sd_bus_message_rewind(3). don't say I didn't warn you π
π EXAMPLES π
here's what the output looks like for a signal message (with SD_BUS_MESSAGE_DUMP_WITH_HEADER) β obsessed with how pretty this is ngl:
> Type=signal Endian=l Flags=1 Version=1 Cookie=22
Path=/value/a Interface=org.freedesktop.DBus.Properties Member=PropertiesChanged
MESSAGE "sa{sv}as" {
STRING "org.freedesktop.systemd.ValueTest";
ARRAY "{sv}" {
DICT_ENTRY "sv" {
STRING "Value";
VARIANT "s" {
STRING "object 0x1e, path /value/a";
};
};
};
ARRAY "s" {
STRING "Value2";
STRING "AnExplicitProperty";
};
};
see?? nested and everything. ate. π
π₯ RETURN VALUE π₯
on success, this function returns 0 or a positive integer. on failure, it returns a negative errno-style error code. and get this β no error codes are currently defined. so like, it fails in theory but there's nothing specific to tell you about it yet. π€·βοΈ
π 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. π«Ά - 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 nicely, one thread at a time, periodt. π§
- 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 yoursetenv()calls in an early phase of the program, when no other threads have been started yet. do it early, bestie, and then never touch it again π
π SEE ALSO π
systemd(1), sd-bus(3), sd-json(3)
and that's the page!! π stay hydrated, rewind your read pointers, and go dump some messages. this has been SD_BUS_MESSAGE_DUMP(3) from systemd 262.1 β mwah, ily, bye bestie πΈβ¨π
π¦ where this page comes from
- arch rolling: systemd-libs 262.1-1 Β· LGPL-2.1-or-later AND CC0-1.0 AND GPL-2.0-or-later WITH Linux-syscall-note
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms