SD_BUS_MESSAGE_GET_DESTINATION(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 is NULL if message is NULL, 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 β€” the message parameter or the output parameter is NULL. basically you forgot to pass something. iconically common mistake, no shame πŸ’œ
  • -EPERM β€” only for sd_bus_message_set_destination() and sd_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 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, 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 call setenv(3) from a parallel thread. recommendation: only do setenv() 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() and sd_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(), and sd_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