SD_BUS_MEMBER_NAME_IS_VALID(3)

πŸ’… SD_BUS_INTERFACE_NAME_IS_VALID πŸ’…

okay so bestie, welcome to the sd_bus_interface_name_is_valid(3) page β€” like, this is the sd_bus_interface_name_is_valid family of functions from the systemd man pages, and honestly it's giving "tiny vibe-check helpers that save you from embarrassing typos in your D-Bus strings" πŸ¦‹ ngl it's kind of iconic in a quiet way.


✨ NAME ✨

sd_bus_interface_name_is_valid, sd_bus_service_name_is_valid, sd_bus_member_name_is_valid, sd_bus_object_path_is_valid β€” check if a string is a valid bus name or object path πŸŽ€ like, are you actually a real name or are you lying to me


🌸 SYNOPSIS 🌸

#include <systemd/sd-bus.h>

int sd_bus_interface_name_is_valid(const char* p);

int sd_bus_service_name_is_valid(const char* p);

int sd_bus_member_name_is_valid(const char* p);

int sd_bus_object_path_is_valid(const char* p);

yes bestie, four whole functions, all taking const char* p, all returning int. copy them exactly, don't get creative with the types πŸ’€


πŸ’– DESCRIPTION πŸ’–

so sd_bus_interface_name_is_valid() checks whether a given string p is a syntactically valid bus interface name. lowkey the whole squad works the same way:

  • sd_bus_service_name_is_valid() β€” checks if the argument is a valid bus service name
  • sd_bus_member_name_is_valid() β€” checks if the argument is a valid bus interface member name
  • sd_bus_object_path_is_valid() β€” checks if the argument is a valid bus object path

and what do they actually do? they generally check that only allowed characters are used βœ… and that the length of the string is within limits πŸ“ like a little bouncer at the club door of D-Bus, checking your ID and also that you're not too tall. periodt.


⭐ RETURN VALUE ⭐

  • 1 β€” slay, the argument is a valid interface / service / member name or object path πŸ’…
  • 0 β€” nope, it is not πŸ™ˆ

and if the argument is NULL? an error is returned. not cute, but like, fair.

πŸ₯Ί Errors

returned errors may indicate the following problems, bestie:

  • -EINVAL β€” the p parameter is NULL. that's it. that's the error. it's giving "you forgot to pass anything" 😭

🧚 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. iconic linking behaviour, no notes.

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 toy, but not at the exact same moment, iykyk.

⚠️ okay this part actually matters, don't skip it: the code described here uses getenv(3), which is declared to be not multi-thread-safe 🚨 that 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. fr fr, do your env stuff first and get it over with πŸ’€

🌈 HISTORY 🌈

sd_bus_interface_name_is_valid(), sd_bus_service_name_is_valid(), sd_bus_member_name_is_valid(), and sd_bus_object_path_is_valid() were added in version 246. a little vintage moment for the girlies who appreciate a stable API πŸŽ€


πŸ‘‘ SEE ALSO πŸ‘‘


and that's the page bestie πŸ’œ that was systemd 261.3, dated SD_BUS_IN..._IS_VALID(3) β€” go forth and validate your bus strings, you're gonna do amazing πŸ¦‹βœ¨πŸŽ€

πŸ“¦ where this page comes from