1SD_SESSION_IS_ACTIVE(3)      sd_session_is_active      SD_SESSION_IS_ACTIVE(3)
2
3
4

NAME

6       sd_session_is_active, sd_session_is_remote, sd_session_get_state,
7       sd_session_get_uid, sd_session_get_username, sd_session_get_seat,
8       sd_session_get_start_time, sd_session_get_service, sd_session_get_type,
9       sd_session_get_class, sd_session_get_desktop, sd_session_get_display,
10       sd_session_get_tty, sd_session_get_vt, sd_session_get_remote_host,
11       sd_session_get_remote_user, sd_session_get_leader - Determine state of
12       a specific session
13

SYNOPSIS

15       #include <systemd/sd-login.h>
16
17       int sd_session_is_active(const char *session);
18
19       int sd_session_is_remote(const char *session);
20
21       int sd_session_get_state(const char *session, char **state);
22
23       int sd_session_get_uid(const char *session, uid_t *uid);
24
25       int sd_session_get_username(const char *session, char **username);
26
27       int sd_session_get_seat(const char *session, char **seat);
28
29       int sd_session_get_start_time(const char *session, uint64_t *usec);
30
31       int sd_session_get_service(const char *session, char **service);
32
33       int sd_session_get_type(const char *session, char **type);
34
35       int sd_session_get_class(const char *session, char **class);
36
37       int sd_session_get_desktop(const char *session, char **desktop);
38
39       int sd_session_get_display(const char *session, char **display);
40
41       int sd_session_get_leader(const char *session, pid_t *leader);
42
43       int sd_session_get_remote_host(const char *session,
44                                      char **remote_host);
45
46       int sd_session_get_remote_user(const char *session,
47                                      char **remote_user);
48
49       int sd_session_get_tty(const char *session, char **tty);
50
51       int sd_session_get_vt(const char *session, unsigned int *vt);
52

DESCRIPTION

54       sd_session_is_active() may be used to determine whether the session
55       identified by the specified session identifier is currently active
56       (i.e. currently in the foreground and available for user input) or not.
57
58       sd_session_is_remote() may be used to determine whether the session
59       identified by the specified session identifier is a remote session
60       (i.e. its remote host is known) or not.
61
62       sd_session_get_state() may be used to determine the state of the
63       session identified by the specified session identifier. The following
64       states are currently known: "online" (session logged in, but session
65       not active, i.e. not in the foreground), "active" (session logged in
66       and active, i.e. in the foreground), "closing" (session nominally
67       logged out, but some processes belonging to it are still around). In
68       the future additional states might be defined, client code should be
69       written to be robust in regards to additional state strings being
70       returned. This function is a more generic version of
71       sd_session_is_active(). The returned string needs to be freed with the
72       libc free(3) call after use.
73
74       sd_session_get_uid() may be used to determine the user identifier of
75       the Unix user the session identified by the specified session
76       identifier belongs to.
77
78       sd_session_get_username() may be used to determine the name of the Unix
79       user the session identified by the specified session identifier belongs
80       to. The returned string needs to be freed with the libc free(3) call
81       after use.
82
83       sd_session_get_seat() may be used to determine the seat identifier of
84       the seat the session identified by the specified session identifier
85       belongs to. Note that not all sessions are attached to a seat, this
86       call will fail (returning -ENODATA) for them. The returned string needs
87       to be freed with the libc free(3) call after use.
88
89       sd_session_get_start_time() may be used to determine the start time of
90       the session identified by the specified session identifier belongs to.
91       The usec is in microseconds since the epoch (CLOCK_REALTIME).
92
93       sd_session_get_service() may be used to determine the name of the
94       service (as passed during PAM session setup) that registered the
95       session identified by the specified session identifier. The returned
96       string needs to be freed with the libc free(3) call after use.
97
98       sd_session_get_type() may be used to determine the type of the session
99       identified by the specified session identifier. The returned string is
100       one of "x11", "wayland", "tty", "mir" or "unspecified" and needs to be
101       freed with the libc free(3) call after use.
102
103       sd_session_get_class() may be used to determine the class of the
104       session identified by the specified session identifier. The returned
105       string is one of "user", "greeter", "lock-screen", or "background" and
106       needs to be freed with the libc free(3) call after use.
107
108       sd_session_get_desktop() may be used to determine the brand of the
109       desktop running on the session identified by the specified session
110       identifier. This field can be set freely by desktop environments and
111       does not follow any special formatting. However, desktops are strongly
112       recommended to use the same identifiers and capitalization as for
113       $XDG_CURRENT_DESKTOP, as defined by the Desktop Entry Specification[1].
114       The returned string needs to be freed with the libc free(3) call after
115       use.
116
117       sd_session_get_display() may be used to determine the X11 display of
118       the session identified by the specified session identifier. The
119       returned string needs to be freed with the libc free(3) call after use.
120
121       sd_session_get_leader() may be used to determine the PID of the leader
122       of the session identified by the specified session identifier.
123
124       sd_session_get_remote_host() may be used to determine the remote
125       hostname of the session identified by the specified session identifier.
126       The returned string needs to be freed with the libc free(3) call after
127       use.
128
129       sd_session_get_remote_user() may be used to determine the remote
130       username of the session identified by the specified session identifier.
131       The returned string needs to be freed with the libc free(3) call after
132       use. Note that this value is rarely known to the system, and even then
133       should not be relied on.
134
135       sd_session_get_tty() may be used to determine the TTY device of the
136       session identified by the specified session identifier. The returned
137       string needs to be freed with the libc free(3) call after use.
138
139       sd_session_get_vt() may be used to determine the VT number of the
140       session identified by the specified session identifier. This function
141       will return an error if the seat does not support VTs.
142
143       If the session parameter of any of these functions is passed as NULL,
144       the operation is executed for the session the calling process is a
145       member of, if there is any.
146

RETURN VALUE

148       If the test succeeds, sd_session_is_active() and sd_session_is_remote()
149       return a positive integer; if it fails, 0. On success,
150       sd_session_get_state(), sd_session_get_uid(),
151       sd_session_get_username(), sd_session_get_seat(),
152       sd_session_get_service(), sd_session_get_type(),
153       sd_session_get_class(), sd_session_get_display(),
154       sd_session_get_leader(), sd_session_get_remote_user(),
155       sd_session_get_remote_host() and sd_session_get_tty() return 0 or a
156       positive integer. On failure, these calls return a negative errno-style
157       error code.
158
159   Errors
160       Returned errors may indicate the following problems:
161
162       -ENXIO
163           The specified session does not exist.
164
165       -ENODATA
166           The given field is not specified for the described session.
167
168       -EINVAL
169           An input parameter was invalid (out of range, or NULL, where that
170           is not accepted).
171
172       -ENOMEM
173           Memory allocation failed.
174

NOTES

176       Functions described here are available as a shared library, which can
177       be compiled against and linked to with the libsystemd pkg-config(1)
178       file.
179
180       The code described here uses getenv(3), which is declared to be not
181       multi-thread-safe. This means that the code calling the functions
182       described here must not call setenv(3) from a parallel thread. It is
183       recommended to only do calls to setenv() from an early phase of the
184       program when no other threads have been started.
185

SEE ALSO

187       systemd(1), sd-login(3), sd_pid_get_session(3)
188

NOTES

190        1. Desktop Entry Specification
191           https://standards.freedesktop.org/desktop-entry-spec/latest/
192
193
194
195systemd 254                                            SD_SESSION_IS_ACTIVE(3)
Impressum