SD_MACHINE_GET_CLASS(3)
π SD_MACHINE_GET_CLASS(3) β bestie edition β¨
okay so this is the sd_machine_get_class page from the sd_machine_get_class section 3 manual, and no cap it's lowkey one of the cutest little queries in all of systemd. it's giving "who dis" but for VMs and containers π«Ά
πΈ NAME πΈ
sd_machine_get_class, sd_machine_get_ifindices β figure out the class and the network interface indices of a virtual machine or container that's running locally on your machine π
β¨ SYNOPSIS β¨
#include <systemd/sd-login.h>
int sd_machine_get_class(const char* machine, char **class);
int sd_machine_get_ifindices(const char* machine, int **ret_ifindices);
π¦ DESCRIPTION π¦
So sd_machine_get_class() is your girl for finding out the class of a locally running virtual machine or container that's registered with systemd-machined.service(8). The string it hands back is either "vm" or "container" β that's it, that's the whole vibe check π
π bestie please don't forget: the returned string needs to be freed with the libc free(3) call after use. don't leave it hanging, that's rude.
Then there's sd_machine_get_ifindices() β she tells you the numeric indices of the network interfaces on the host that are pointing towards the specified locally running virtual machine or container π₯ the vm or container has to be registered with systemd-machined.service(8) for this to work, periodt.
you can pass the output parameter ret_ifindices as NULL when you don't actually need the output value β very "no thoughts head empty" of you, and honestly valid π
π also freeing time: the returned array needs to be freed with the libc free(3) call after use. same energy as before, okay?
π RETURN VALUE π
On success, these functions return a non-negative integer β¨ slay. Specifically, sd_machine_get_ifindices() returns the number of the relevant network interfaces π’
On failure, these calls return a negative errno-style error code π keep that in mind.
π Errors
Returned errors may indicate the following problems, iykyk:
-ENXIOβ the specified machine does not exist or is currently not running. she's not here, she's offline, she's on a break π-EINVALβ an input parameter was invalid (out of range, orNULL, where that is not accepted). basically you handed her something she can't work with π-ENOMEMβ memory allocation failed. the vibes ran out of RAM π
π§ 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 π«Ά icon behaviour, honestly.
β οΈ and here's the serious one, bestie, listen up: the code described here usesgetenv(3), which is declared to be not multi-thread-safe. This means that the code calling the functions described here must not callsetenv(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 β like, get it done first, then start the threads. main character scheduling energy.
π HISTORY π
sd_machine_get_class() and sd_machine_get_ifindices() were added in version 217 π retro queens.
π SEE ALSO π
systemd(1), sd-login(3), systemd-machined.service(8), sd_pid_get_machine_name(3)
go read those next, bestie, they all slay in their own way πΈ
and that's the whole page!! brought to you by systemd 261.3 on the SD_MACHINE_GET_CLASS(3) tip β 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