SD_BUS_ME...GET_COOKIE(3)
πΈ NAME πΈ
ok so bestie, these two functions β sd_bus_message_get_cookie and sd_bus_message_get_reply_cookie β literally just return the transaction cookie of a message. that's it. that's the whole vibe. πͺ
β¨ SYNOPSIS β¨
#include <systemd/sd-bus.h>
int sd_bus_message_get_cookie(sd_bus_message *message,
uint64_t *cookie);
int sd_bus_message_get_reply_cookie(sd_bus_message *message,
uint64_t *cookie);
π DESCRIPTION π
okay so picture this: sd_bus_message_get_cookie() hands you back the transaction cookie of a message. highkey iconic. and before you ask β the cookie uniquely identifies a message within each bus peer, but it is not globally unique (iykyk, don't @ me). it gets assigned when a message is sent. so no message, no cookie, periodt. π«Ά
then we have sd_bus_message_get_reply_cookie() β this one returns the transaction cookie of the message that the specified message is a response to. like, when a reply message is generated for a method call message, its cookie is copied over into this field. the way that works?? honestly kind of genius. β
β οΈ but bestie, listen: while every message that is transferred is identified by a cookie, only response messages carry a reply cookie field. so don't go looking for reply cookies where there aren't any. π
both functions take a message object as the first parameter, plus a place to store the 64-bit cookie in. easy. slay. π
π₯ RETURN VALUE π₯
on success, these calls return 0 or a positive integer. on failure, they return a negative errno-style error code. no in-between, no drama (well, the negative ones are drama). π
on success, the cookie / reply cookie is returned in the specified 64-bit unsigned integer variable. π
π Errors
returned errors may indicate the following problems, and yes, they're giving main character energy:
-EINVALβ a specified parameter is invalid. lowkey your bad. π-ENODATAβ no cookie has been assigned to this message. this either means the message has not been sent yet (so obviously no cookie, she hasn't even left the house π ), or that the message is not a method response message and hence carries a reply cookie field. so double-check which one you're calling, bestie. π«Ά
π NOTES π
the functions described here are available as a shared library, which can be compiled against and linked to with the libsystemd pkg-config(1) file. very convenient, very demure. β¨
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, not the moment. π¦
π¨ also, 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. the recommendation is to only do calls tosetenv()from an early phase of the program, when no other threads have been started. fr fr, do not test this. π§
π HISTORY π
sd_bus_message_get_cookie() and sd_bus_message_get_reply_cookie() were added in version 209. vintage. iconic. she's been serving since 209. β
π¦ SEE ALSO π¦
okay that's the whole page, you ate that π
this little number came to you straight from systemd 261.3, page SD_BUS_ME...GET_COOKIE(3) β go forth and read those cookies bestie, ily, 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