SD_BUS_RE...THOD_ERROR(3)
π SD_BUS_RE...THOD_ERROR(3) π
okay so bestie, welcome to sd_bus_reply_method_error β part of the sd_bus_reply_method_error family in the sd_bus_reply_method_error section of the manual. yes the header truncated the name, no that's not my fault, it's giving "long function name problems" π. the actual manual name is sd_bus_reply_method_error and today we're learning how to politely tell a D-Bus caller "girl, no" π
β¨ NAME β¨
sd_bus_reply_method_error, sd_bus_reply_method_errorf, sd_bus_reply_method_errorfv, sd_bus_reply_method_errno, sd_bus_reply_method_errnof, sd_bus_reply_method_errnofv β reply with an error to a D-Bus method call π
like, the call came in, you looked at it, and you're sending back a no. iconic behavior tbh.
πΈ SYNOPSIS πΈ
#include <systemd/sd-bus.h>
int sd_bus_reply_method_error(sd_bus_message *call,
const sd_bus_error *e);
int sd_bus_reply_method_errorf(sd_bus_message *call, const char *name,
const char *format, ...);
int sd_bus_reply_method_errorfv(sd_bus_message *call, const char *name,
const char *format, va_list ap);
int sd_bus_reply_method_errno(sd_bus_message *call, int error,
const sd_bus_error *p);
int sd_bus_reply_method_errnof(sd_bus_message *call, int error,
const char *format, ...);
int sd_bus_reply_method_errnofv(sd_bus_message *call, int error,
const char *format, va_list ap);
six whole functions, all baddies, all doing the "sorry not sorry" reply π
π¦ DESCRIPTION π¦
so. sd_bus_reply_method_error() sends an error reply to the call message. the error structure e specifies the error you're sending, and it gets used exactly as described over in sd_bus_message_new_method_error(3) β go read that one, it's the source of truth, iykyk. and here's the cute part: if no reply is expected to call, this function succeeds without sending a reply at all. she just... doesn't. main character energy π
then we got the vibe-check cousins, all defined by β¨analogyβ¨:
sd_bus_reply_method_errorf()is tosd_bus_reply_method_error()whatsd_bus_message_new_method_errorf()is tosd_bus_message_new_method_error()π«Άsd_bus_reply_method_errno()is tosd_bus_reply_method_error()whatsd_bus_message_new_method_errno()is tosd_bus_message_new_method_error()π«Άsd_bus_reply_method_errnof()is tosd_bus_reply_method_error()whatsd_bus_message_new_method_errnof()is tosd_bus_message_new_method_error()π«Ά
the pattern is literally right there, bestie. f = formatted, v = you brought a va_list, errno = you're passing an int error. slay.
π RETURN VALUE π
this function returns a non-negative integer if the error reply was successfully sent or if call doesn't expect a reply (yes, both. she's flexible π). on failure it returns a negative errno-style error code. no cap.
π Errors π
the returned errors may indicate these problems, and honestly? mood:
-EINVALβ multiple ways to disappoint her:- the input parameter
callisNULLπ« - message
callis not a method call message - message
callis not attached to a bus - the error parameter
etosd_bus_reply_method_error()is not set, seesd_bus_error_is_set(3)
- the input parameter
-EPERMβ messagecallhas been sealed π (locked, done, no touching)-ENOTCONNβ the bus to which messagecallis attached is not connected β-ENOMEMβ memory allocation failed π
oh and also: any error returned by sd_bus_send(3) may be returned too. so like, surprise errors are on the table. π
π§ 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. multiple independent objects may be used from different threads in parallel. so like... share the object, but take turns. periodt. π
- the code described here uses
getenv(3), which is declared to be not multi-thread-safe. which 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. do it first, do it alone, do it early πΈ
π₯ SEE ALSO π₯
systemd(1), sd-bus(3), sd_bus_message_new_method_error(3)
and that's the whole page bestie β¨ this lil slice of wisdom comes to you from systemd 261.3, page SD_BUS_RE...THOD_ERROR(3) β go forth and error-reply responsibly, 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