SD_GET_SEATS(3)
π
SD_GET_SEATS(3) β the sd_get_seats girlies β¨
okay so this is section 3 of the manual, bestie β the sd_get_seats page, and it's literally your cheat sheet for asking systemd "hey who's here rn?"
πΈ NAME πΈ
sd_get_seats, sd_get_sessions, sd_get_uids, sd_get_machine_names β determine available seats, sessions, logged in users and virtual machines/containers π«Ά
like, the whole friend group of functions whose entire job is finding out who and what exists on this system.
β¨ SYNOPSIS β¨
#include <systemd/sd-login.h>
int sd_get_seats(char ***seats);
int sd_get_sessions(char ***sessions);
int sd_get_uids(uid_t **users);
int sd_get_machine_names(char ***machines);
four little functions, one include, zero drama (mostly). π
π DESCRIPTION π
So sd_get_seats() may be used to determine all currently available local seats. It returns the number of seat identifiers, and β if the input pointer is non-NULL β a NULL-terminated array of seat identifiers gets stored at the address. πͺ
β οΈ heads up bestie: the returned array and all strings it references need to be freed with the libc free(3) call after use. don't just walk away from it, that's rude.
Also, no cap: instead of an empty array, NULL may be returned, and you should consider that equivalent to an empty array. it's giving "same thing, different font" π
Similarly, sd_get_sessions() may be used to determine all current login sessions. π§
Similarly, sd_get_uids() may be used to determine all Unix users who currently have login sessions. π
Similarly, sd_get_machine_names() may be used to determine all current virtual machines and containers on the system. π₯οΈβ¨
note that the returned lists are not sorted and come in an undefined order. so if you're expecting alphabetical, that's not the vibe check you're getting π
β RETURN VALUE β
On success, sd_get_seats(), sd_get_sessions(), sd_get_uids() and sd_get_machine_names() return the number of entries in the arrays. slay. π
On failure, these calls return a negative errno-style error code. sad girl hours π
π¦ Errors π¦
Returned errors may indicate the following problems:
-ENOMEMβ Memory allocation failed. that's it, that's the whole error. the malloc said no π
π 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. πβ¨
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. like, set it up before the party starts, not mid-party. periodt. π
π HISTORY π
sd_get_machine_names() was added in version 203. she's not the newest but she IS iconic π
π₯ SEE ALSO π₯
systemd(1), sd-login(3), sd_session_get_seat(3)
go read those next, iykyk π«Ά
and that's the page!! brought to you by systemd 261.3 β the version that signed the group chat, 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