SD_BUS_ME...PEND_BASIC(3)

🌸 NAME 🌸

okay so bestie, welcome to the sd_bus_message_append_basic page (that's SD_BUS_ME...PEND_BASIC(3) in the manual, section 3 β€” the truncated name is literally how it shows up in the header, iykyk πŸ’…). this one does exactly what it says on the tin:

sd_bus_message_append_basic β€” Attach a single field to a message ✨


πŸŽ€ SYNOPSIS πŸŽ€

#include <systemd/sd-bus.h>

int sd_bus_message_append_basic(sd_bus_message *m, char type,
                                const void *p);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so sd_bus_message_append_basic() appends a single field to the message m. one field. one. don't get greedy πŸ”₯

the parameter type is the main character here β€” it decides how the pointer p gets interpreted πŸ‘‘. type has got to be one of the basic types as defined by the Basic Types[1] section of the D-Bus specification, and they're all listed in the very cute table below πŸ’–.

Table 1. Item type specifiers (the whole squad, no gatekeeping):

  • "y" β€” constant SD_BUS_TYPE_BYTE β€” unsigned integer β€” size: 1 byte β€” expected C type: uint8_t
  • "b" β€” constant SD_BUS_TYPE_BOOLEAN β€” boolean β€” size: 4 bytes β€” expected C type: int
  • "n" β€” constant SD_BUS_TYPE_INT16 β€” signed integer β€” size: 2 bytes β€” expected C type: int16_t
  • "q" β€” constant SD_BUS_TYPE_UINT16 β€” unsigned integer β€” size: 2 bytes β€” expected C type: uint16_t
  • "i" β€” constant SD_BUS_TYPE_INT32 β€” signed integer β€” size: 4 bytes β€” expected C type: int32_t
  • "u" β€” constant SD_BUS_TYPE_UINT32 β€” unsigned integer β€” size: 4 bytes β€” expected C type: uint32_t
  • "x" β€” constant SD_BUS_TYPE_INT64 β€” signed integer β€” size: 8 bytes β€” expected C type: int64_t
  • "t" β€” constant SD_BUS_TYPE_UINT64 β€” unsigned integer β€” size: 8 bytes β€” expected C type: uint64_t
  • "d" β€” constant SD_BUS_TYPE_DOUBLE β€” floating-point β€” size: 8 bytes β€” expected C type: double
  • "s" β€” constant SD_BUS_TYPE_STRING β€” Unicode string β€” size: variable β€” expected C type: char[]
  • "o" β€” constant SD_BUS_TYPE_OBJECT_PATH β€” object path β€” size: variable β€” expected C type: char[]
  • "g" β€” constant SD_BUS_TYPE_SIGNATURE β€” signature β€” size: variable β€” expected C type: char[]
  • "h" β€” constant SD_BUS_TYPE_UNIX_FD β€” UNIX file descriptor β€” size: 4 bytes β€” expected C type: int

so here's the vibe on copying 🫢: the value of the parameter gets copied into a memory area held by the message object. so the value stays in the possession of the caller β€” meaning you can freely change it after this call and the bus message you already added it to will not care one bit, no cap ✨. and if type is "h" (UNIX file descriptor), the descriptor is duplicated by this call, and the descriptor you passed stays in possession of the caller. slay, no dangling FDs πŸ’….

for types "s", "o", and "g", the parameter p is interpreted as a pointer to a NUL-terminated character sequence. and as a special case, a NULL pointer is interpreted as an empty string πŸ™ˆ. the string should be a valid Unicode string encoded as UTF-8. and for the two latter types ("o" and "g"), the additional requirements for a D-Bus object path or type signature should be satisfied too. those requirements should be verified by the recipient of the message β€” that's their job, not yours, bestie 😭


⭐ RETURN VALUE ⭐

on success, this call returns 0 or a positive integer πŸ’š. on failure, it returns a negative errno-style error code πŸ’€.

πŸ”₯ Errors

returned errors may indicate the following problems:

  • -EINVAL β€” specified parameter is invalid.
  • -EPERM β€” message has been sealed. (no editing, it's locked, periodt πŸ”’)
  • -ESTALE β€” message is in invalid state.
  • -ENXIO β€” message cannot be appended to.
  • -ENOMEM β€” memory allocation failed.

🧚 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 🌈.

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 objects, don't share the moment 🫢.

⚠️ okay this part matters so listen up: the code described here uses getenv(3), which is declared to be not multi-thread-safe. this means the code calling the functions described here must not call setenv(3) from a parallel thread. it is recommended to only do calls to setenv() from an early phase of the program when no other threads have been started. highkey do this early, bestie πŸ’€

πŸ’œ SEE ALSO πŸ’œ

systemd(1), sd-bus(3), sd_bus_message_read_basic(3), sd_bus_message_append(3), The D-Bus specification[2]


πŸ“ NOTES πŸ“

  1. Basic Types β€” https://dbus.freedesktop.org/doc/dbus-specification.html#basic-types
  2. The D-Bus specification β€” https://dbus.freedesktop.org/doc/dbus-specification.html

and that's the whole page, bestie β€” brought to you by systemd 261.3 on the SD_BUS_ME...PEND_BASIC(3) manual page, go append something iconic today πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from