SD_BUS_MESSAGE_GET_PATH(3)
π sd_bus_message_set_destination β bestie's guide to bus message addressing β¨
okay so this is the sd-bus.h girlies' guide to who is this message for, where is it going, and who even sent it β all the addressing tea, from the sd-bus(3) family of manual pages in the systemd docs. let's get into it π«Ά
πΈ NAME πΈ
sd_bus_message_set_destination, sd_bus_message_get_destination, sd_bus_message_get_path, sd_bus_message_get_interface, sd_bus_message_get_member, sd_bus_message_set_sender, sd_bus_message_get_sender β literally the whole squad that sets and queries bus message addressing information. no cap, that's the entire job π
β¨ SYNOPSIS β¨
#include <systemd/sd-bus.h>
int sd_bus_message_set_destination(sd_bus_message *message,
const char *destination);
const char* sd_bus_message_get_destination(sd_bus_message *message);
const char* sd_bus_message_get_path(sd_bus_message *message);
const char* sd_bus_message_get_interface(sd_bus_message *message);
const char* sd_bus_message_get_member(sd_bus_message *message);
int sd_bus_message_set_sender(sd_bus_message *message,
const char *sender);
const char* sd_bus_message_get_sender(sd_bus_message *message);
π DESCRIPTION π
the setters, aka the ones that actually do something π
sd_bus_message_set_destination() sets the destination service name on the bus message object you hand it. the name you pass has to be a valid unique service name or a well-known service name β pick one, bestie, those are the rules π₯
sd_bus_message_set_sender() sets the sender service name on the message. same deal: valid unique or well-known service name, no exceptions. quick heads up though β this one is only useful for messages you're sending on direct connections, because when you're talking to a bus broker the broker just fills in that field itself, and whatever sender the original sender set gets ignored. so likeβ¦ it's giving "for the direct-connection girlies only" π
the getters, aka the ones that spill the tea π
sd_bus_message_get_destination(), sd_bus_message_get_path(), sd_bus_message_get_interface(), and sd_bus_message_get_member() return the destination, path, interface, and member fields straight out of the message header.
sd_bus_message_get_sender() returns the sender field from the message.
π real talk: the return value isNULLifmessageisNULL, or if the message is of a type that doesn't use those fields, or if the message just doesn't have them set. not every message uses every field, and that's fine, we don't judge.
if you want the deep lore on what those values actually mean, go check sd_bus_message_new_method_call(3) and sd_bus_message_set_destination(3) β they discuss it way more.
β οΈ the string ownership situation (important, bestie) β οΈ
when a string comes back to you, it's a pointer to internal storage β do not modify it, do not free it, that's not your bag. it's only valid as long as the message is still referenced and that field hasn't been changed by some other call. the moment somebody else touches it, your string is a ghost π»
π¦ RETURN VALUE π¦
slay, so: on success these calls return 0 or a positive integer. on failure they return a negative errno-style error code. that's it, that's the vibe check π
π Errors
here's the drama these calls might throw at you:
-EINVALβ themessageparameter or the output parameter isNULL. basically you forgot to pass something. iconically common mistake, no shame π-EPERMβ only forsd_bus_message_set_destination()andsd_bus_message_set_sender(): the message is already sealed. you can't write to it anymore, periodt π-EEXISTβ the message already has a destination or sender field set. it's taken, babes. something (or someone) got there first β¨
π NOTES π
- these functions are available as a shared library, and you can compile against and link to them 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, but not at the same time. be polite π«Ά
- the code described here uses
getenv(3), which is declared not multi-thread-safe. this means any code calling the functions described here must not callsetenv(3)from a parallel thread. recommendation: only dosetenv()calls from an early phase of the program, before any other threads have been started. don't be messy with it π
β HISTORY β
sd_bus_message_set_destination()andsd_bus_message_set_sender()were added in version 237.sd_bus_message_get_destination(),sd_bus_message_get_path(),sd_bus_message_get_interface(),sd_bus_message_get_member(), andsd_bus_message_get_sender()were added in version 240.
the setters really said "we were here first" π
π SEE ALSO π
systemd(1), sd-bus(3), sd_bus_new(3), sd_bus_set_sender(3)
and that's the whole page, bestie! this one's from the systemd docs, version 261.3, dated according to that footer β go forth and address your messages correctly πβ¨π
π¦ 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