SD_SEAT_GET_ACTIVE(3)
π SD_SEAT_GET_ACTIVE π
okay so bestie, this is a page from the sd_seat_get_active corner of the systemd manual (section 3, library calls, you know the vibe) and it's literally all about finding out what's going on with a specific seat. no cap, it's more useful than it sounds.
β¨ NAME β¨
sd_seat_get_active, sd_seat_get_sessions, sd_seat_can_tty, sd_seat_can_graphical β figure out the state of one specific seat πͺ
πΈ SYNOPSIS πΈ
#include <systemd/sd-login.h>
int sd_seat_get_active(const char *seat, char **session, uid_t *uid);
int sd_seat_get_sessions(const char *seat, char ***ret_sessions,
uid_t **ret_uids, unsigned int *ret_n_uids);
int sd_seat_can_tty(const char *seat);
int sd_seat_can_graphical(const char *seat);
π¦ DESCRIPTION π¦
π
sd_seat_get_active()
so this one tells you which session is currently active on a seat β if there even is one, which, mood. it hands you back the session identifier and the user identifier of the Unix user that session belongs to. you can pass NULL for either the session or the user identifier parameter if you only wanna query one of them, no pressure. the returned string? you gotta free it with the libc free(3) call after use. don't forget, bestie, that's a leak waiting to happen π
π sd_seat_get_sessions()
this one gives you all the sessions on the specified seat. it returns two arrays: one is NULL-terminated and holds the session identifiers, and the other holds the user identifiers of the Unix users those sessions belong to. there's an extra parameter you can use to get the number of entries in that latter array β and fun fact, that value is the same as the return value, as long as the return value is nonnegative. you can pass any of the output parameters as NULL if you don't need those values. the arrays and the strings they point at all need freeing with the libc free(3) call after use. β οΈ and heads up: instead of an empty array, NULL may be returned, and you should consider that equivalent to an empty array. slay, but also, be careful.
π sd_seat_can_tty()
does this specific seat provide TTY functionality, i.e. is it useful as a text console? that's the whole question. yes or no, iconically.
β sd_seat_can_graphical()
does this specific seat provide graphics functionality, i.e. is it useful as a graphics display? same energy, different vibes.
π«Ά and here's the group-chat PSA: if you pass the seat parameter of any of these functions as NULL, the operation gets executed for the seat of the session of the calling process β if there is any. so like, it just does the thing for your own seat. convenient.
π RETURN VALUE π
on success, sd_seat_get_active() returns 0 or a positive integer. periodt.
on success, sd_seat_get_sessions() returns the number of entries in the session identifier array. iconic.
if the test succeeds, sd_seat_can_tty() and sd_seat_can_graphical() return a positive integer β and if it fails, 0. that's it, that's the whole answer.
on failure, these calls return a negative errno-style error code. π
π Errors
the returned errors may indicate the following problems, and yes you should actually read them:
-ENODATAβ the given field is not specified for the described seat. it's just not there, bestie.-ENXIOβ the specified seat is unknown. who is she? never heard of her.-EINVALβ an input parameter was invalid (out of range, orNULLwhere that is not accepted). read the docs before you @ me.-ENOMEMβ memory allocation failed. rip.
π§ NOTES π§
the functions described here are available as a shared library, which you can compile against and link to with the libsystemd pkg-config(1) file. standard stuff, but now you know β¨
π lowkey important: the code described here usesgetenv(3), which is declared to be not multi-thread-safe. that means 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 yet. do not skip this part, i'm begging π«Ά
πΈ HISTORY πΈ
sd_seat_can_tty() and sd_seat_can_graphical() were added in version 186. they're the OGs of this page, honestly.
π SEE ALSO π
systemd(1), sd-login(3), sd_session_get_seat(3)
and that's the whole page, bestie!! go forth and query some seats πβ¨ this little love letter came to you courtesy of systemd 261.3 β mwah, see you in the next manpage ππ¦
π¦ 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