sd-login — APIs for tracking logins
pkg-config --cflags --libs libsystemd
sd-login.h provides APIs to introspect
and monitor seat, login session and user status information on the
See Multi-Seat on Linux for an introduction into multi-seat support on Linux, the background for this set of APIs.
Note that these APIs only allow purely passive access and monitoring of seats, sessions and users. To actively make changes to the seat configuration, terminate login sessions, or switch session on a seat you need to utilize the D-Bus API of systemd-logind, instead.
These functions synchronously access data in
/run. All of these are virtual file
systems, hence the runtime cost of the accesses is relatively
It is possible (and often a very good choice) to mix calls
to the synchronous interface of
with the asynchronous D-Bus interface of systemd-logind. However,
if this is done you need to think a bit about possible races since
the stream of events from D-Bus and from
sd-login.h interfaces such as the login
monitor are asynchronous and not ordered against each
If the functions return string arrays, these are generally
NULL terminated and need to be freed by the
caller with the libc
call after use, including the strings referenced therein.
Similarly, individual strings returned need to be freed, as
As a special exception, instead of an empty string array
NULL may be returned, which should be treated
equivalent to an empty string array.
These APIs are implemented as a shared
library, which can be compiled and linked to with the