Debian Codegraph @

man/sd_session_is_active.xml

raw
1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
5
6 <refentry id="sd_session_is_active" conditional='HAVE_PAM'
7 xmlns:xi="http://www.w3.org/2001/XInclude">
8
9 <refentryinfo>
10 <title>sd_session_is_active</title>
11 <productname>systemd</productname>
12 </refentryinfo>
13
14 <refmeta>
15 <refentrytitle>sd_session_is_active</refentrytitle>
16 <manvolnum>3</manvolnum>
17 </refmeta>
18
19 <refnamediv>
20 <refname>sd_session_is_active</refname>
21 <refname>sd_session_is_remote</refname>
22 <refname>sd_session_get_state</refname>
23 <refname>sd_session_get_uid</refname>
24 <refname>sd_session_get_username</refname>
25 <refname>sd_session_get_seat</refname>
26 <refname>sd_session_get_start_time</refname>
27 <refname>sd_session_get_service</refname>
28 <refname>sd_session_get_type</refname>
29 <refname>sd_session_get_class</refname>
30 <refname>sd_session_get_desktop</refname>
31 <refname>sd_session_get_display</refname>
32 <refname>sd_session_get_tty</refname>
33 <refname>sd_session_get_vt</refname>
34 <refname>sd_session_get_remote_host</refname>
35 <refname>sd_session_get_remote_user</refname>
36 <refname>sd_session_get_leader</refname>
37 <refname>sd_session_get_extra_device_access</refname>
38 <refpurpose>Determine state of a specific session</refpurpose>
39 </refnamediv>
40
41 <refsynopsisdiv>
42 <funcsynopsis>
43 <funcsynopsisinfo>#include &lt;systemd/sd-login.h&gt;</funcsynopsisinfo>
44
45 <funcprototype>
46 <funcdef>int <function>sd_session_is_active</function></funcdef>
47 <paramdef>const char *<parameter>session</parameter></paramdef>
48 </funcprototype>
49
50 <funcprototype>
51 <funcdef>int <function>sd_session_is_remote</function></funcdef>
52 <paramdef>const char *<parameter>session</parameter></paramdef>
53 </funcprototype>
54
55 <funcprototype>
56 <funcdef>int <function>sd_session_get_state</function></funcdef>
57 <paramdef>const char *<parameter>session</parameter></paramdef>
58 <paramdef>char **<parameter>state</parameter></paramdef>
59 </funcprototype>
60
61 <funcprototype>
62 <funcdef>int <function>sd_session_get_uid</function></funcdef>
63 <paramdef>const char *<parameter>session</parameter></paramdef>
64 <paramdef>uid_t *<parameter>uid</parameter></paramdef>
65 </funcprototype>
66
67 <funcprototype>
68 <funcdef>int <function>sd_session_get_username</function></funcdef>
69 <paramdef>const char *<parameter>session</parameter></paramdef>
70 <paramdef>char **<parameter>username</parameter></paramdef>
71 </funcprototype>
72
73 <funcprototype>
74 <funcdef>int <function>sd_session_get_seat</function></funcdef>
75 <paramdef>const char *<parameter>session</parameter></paramdef>
76 <paramdef>char **<parameter>seat</parameter></paramdef>
77 </funcprototype>
78
79 <funcprototype>
80 <funcdef>int <function>sd_session_get_start_time</function></funcdef>
81 <paramdef>const char *<parameter>session</parameter></paramdef>
82 <paramdef>uint64_t *<parameter>usec</parameter></paramdef>
83 </funcprototype>
84
85 <funcprototype>
86 <funcdef>int <function>sd_session_get_service</function></funcdef>
87 <paramdef>const char *<parameter>session</parameter></paramdef>
88 <paramdef>char **<parameter>service</parameter></paramdef>
89 </funcprototype>
90
91 <funcprototype>
92 <funcdef>int <function>sd_session_get_type</function></funcdef>
93 <paramdef>const char *<parameter>session</parameter></paramdef>
94 <paramdef>char **<parameter>type</parameter></paramdef>
95 </funcprototype>
96
97 <funcprototype>
98 <funcdef>int <function>sd_session_get_class</function></funcdef>
99 <paramdef>const char *<parameter>session</parameter></paramdef>
100 <paramdef>char **<parameter>class</parameter></paramdef>
101 </funcprototype>
102
103 <funcprototype>
104 <funcdef>int <function>sd_session_get_desktop</function></funcdef>
105 <paramdef>const char *<parameter>session</parameter></paramdef>
106 <paramdef>char **<parameter>desktop</parameter></paramdef>
107 </funcprototype>
108
109 <funcprototype>
110 <funcdef>int <function>sd_session_get_display</function></funcdef>
111 <paramdef>const char *<parameter>session</parameter></paramdef>
112 <paramdef>char **<parameter>display</parameter></paramdef>
113 </funcprototype>
114
115 <funcprototype>
116 <funcdef>int <function>sd_session_get_leader</function></funcdef>
117 <paramdef>const char *<parameter>session</parameter></paramdef>
118 <paramdef>pid_t *<parameter>leader</parameter></paramdef>
119 </funcprototype>
120
121 <funcprototype>
122 <funcdef>int <function>sd_session_get_remote_host</function></funcdef>
123 <paramdef>const char *<parameter>session</parameter></paramdef>
124 <paramdef>char **<parameter>remote_host</parameter></paramdef>
125 </funcprototype>
126
127 <funcprototype>
128 <funcdef>int <function>sd_session_get_remote_user</function></funcdef>
129 <paramdef>const char *<parameter>session</parameter></paramdef>
130 <paramdef>char **<parameter>remote_user</parameter></paramdef>
131 </funcprototype>
132
133 <funcprototype>
134 <funcdef>int <function>sd_session_get_tty</function></funcdef>
135 <paramdef>const char *<parameter>session</parameter></paramdef>
136 <paramdef>char **<parameter>tty</parameter></paramdef>
137 </funcprototype>
138
139 <funcprototype>
140 <funcdef>int <function>sd_session_get_vt</function></funcdef>
141 <paramdef>const char *<parameter>session</parameter></paramdef>
142 <paramdef>unsigned int *<parameter>vt</parameter></paramdef>
143 </funcprototype>
144
145 <funcprototype>
146 <funcdef>int <function>sd_session_get_extra_device_access</function></funcdef>
147 <paramdef>const char *<parameter>session</parameter></paramdef>
148 <paramdef>char ***<parameter>ret_ids</parameter></paramdef>
149 </funcprototype>
150 </funcsynopsis>
151 </refsynopsisdiv>
152
153 <refsect1>
154 <title>Description</title>
155
156 <para><function>sd_session_is_active()</function> may be used to
157 determine whether the session identified by the specified session
158 identifier is currently active (i.e. currently in the foreground
159 and available for user input) or not.</para>
160
161 <para><function>sd_session_is_remote()</function> may be used to
162 determine whether the session identified by the specified session
163 identifier is a remote session (i.e. its remote host is known) or
164 not.</para>
165
166 <para><function>sd_session_get_state()</function> may be used to
167 determine the state of the session identified by the specified
168 session identifier. The following states are currently known:
169 <literal>online</literal> (session logged in, but session not
170 active, i.e. not in the foreground), <literal>active</literal>
171 (session logged in and active, i.e. in the foreground),
172 <literal>closing</literal> (session nominally logged out, but some
173 processes belonging to it are still around). In the future
174 additional states might be defined, client code should be written
175 to be robust in regards to additional state strings being
176 returned. This function is a more generic version of
177 <function>sd_session_is_active()</function>. The returned string
178 needs to be freed with the libc
179 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
180 call after use.</para>
181
182 <para><function>sd_session_get_uid()</function> may be used to
183 determine the user identifier of the Unix user the session
184 identified by the specified session identifier belongs to.</para>
185
186 <para><function>sd_session_get_username()</function> may be used to
187 determine the name of the Unix user the session identified by
188 the specified session identifier belongs to. The returned string
189 needs to be freed with the libc
190 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
191 call after use.</para>
192
193 <para><function>sd_session_get_seat()</function> may be used to
194 determine the seat identifier of the seat the session identified
195 by the specified session identifier belongs to. Note that not all
196 sessions are attached to a seat, this call will fail (returning
197 <constant>-ENODATA</constant>) for them. The returned string needs
198 to be freed with the libc
199 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
200 call after use.</para>
201
202 <para><function>sd_session_get_start_time()</function> may be used to
203 determine the start time of the session identified by the specified
204 session identifier belongs to. The <parameter>usec</parameter>
205 is in microseconds since the epoch (<constant>CLOCK_REALTIME</constant>).</para>
206
207 <para><function>sd_session_get_service()</function> may be used to
208 determine the name of the service (as passed during PAM session
209 setup) that registered the session identified by the specified
210 session identifier. The returned string needs to be freed with the
211 libc
212 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
213 call after use.</para>
214
215 <para><function>sd_session_get_type()</function> may be used to
216 determine the type of the session identified by the specified
217 session identifier. The returned string is one of
218 <literal>x11</literal>, <literal>wayland</literal>,
219 <literal>tty</literal>, <literal>mir</literal> or
220 <literal>unspecified</literal> and needs to be freed with the libc
221 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
222 call after use.</para>
223
224 <para><function>sd_session_get_class()</function> may be used to determine the class of the session
225 identified by the specified session identifier. The returned string is one of <literal>user</literal>,
226 <literal>user-early</literal>, <literal>user-light</literal>, <literal>user-early-light</literal>,
227 <literal>user-incomplete</literal>, <literal>greeter</literal>, <literal>lock-screen</literal>,
228 <literal>background</literal>, <literal>background-light</literal>, <literal>manager</literal> or
229 <literal>manager-early</literal> and needs to be freed with the libc <citerefentry
230 project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry> call after
231 use.</para>
232
233 <para><function>sd_session_get_desktop()</function> may be used to
234 determine the brand of the desktop running on the session
235 identified by the specified session identifier. This field can be
236 set freely by desktop environments and does not follow any special
237 formatting. However, desktops are strongly recommended to use the
238 same identifiers and capitalization as for
239 <varname>$XDG_CURRENT_DESKTOP</varname>, as defined by the <ulink
240 url="https://standards.freedesktop.org/desktop-entry-spec/latest/">Desktop
241 Entry Specification</ulink>. The returned string needs to be freed
242 with the libc
243 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
244 call after use.</para>
245
246 <para><function>sd_session_get_display()</function> may be used to
247 determine the X11 display of the session identified by the
248 specified session identifier. The returned string needs to be
249 freed with the libc
250 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
251 call after use.</para>
252
253 <para><function>sd_session_get_leader()</function> may be used to
254 determine the PID of the leader of the session identified by the
255 specified session identifier.</para>
256
257 <para><function>sd_session_get_remote_host()</function> may be
258 used to determine the remote hostname of the session identified by
259 the specified session identifier. The returned string needs to be
260 freed with the libc
261 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
262 call after use.</para>
263
264 <para><function>sd_session_get_remote_user()</function> may be
265 used to determine the remote username of the session identified by
266 the specified session identifier. The returned string needs to be
267 freed with the libc
268 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
269 call after use. Note that this value is rarely known to the
270 system, and even then should not be relied on.</para>
271
272 <para><function>sd_session_get_tty()</function> may be used to
273 determine the TTY device of the session identified by the
274 specified session identifier. The returned string needs to be
275 freed with the libc
276 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
277 call after use.</para>
278
279 <para><function>sd_session_get_vt()</function> may be used to
280 determine the VT number of the session identified by the specified
281 session identifier. This function will return an error if the seat
282 does not support VTs.</para>
283
284 <para><function>sd_session_get_extra_device_access()</function> may
285 be used to determine which additional hardware devices the session
286 is granted access to. For every <literal><replaceable>ID</replaceable></literal>
287 in the list, the session is granted access to all devices tagged with
288 <literal>xaccess-<replaceable>ID</replaceable></literal> in udev.</para>
289
290 <para>If the <varname>session</varname> parameter of any of these
291 functions is passed as <constant>NULL</constant>, the operation is
292 executed for the session the calling process is a member of, if
293 there is any.</para>
294 </refsect1>
295
296 <refsect1>
297 <title>Return Value</title>
298
299 <para>If the test succeeds,
300 <function>sd_session_is_active()</function> and
301 <function>sd_session_is_remote()</function>
302 return a positive integer; if it fails, 0. On success,
303 <function>sd_session_get_state()</function>,
304 <function>sd_session_get_uid()</function>,
305 <function>sd_session_get_username()</function>,
306 <function>sd_session_get_seat()</function>,
307 <function>sd_session_get_service()</function>,
308 <function>sd_session_get_type()</function>,
309 <function>sd_session_get_class()</function>,
310 <function>sd_session_get_display()</function>,
311 <function>sd_session_get_leader()</function>,
312 <function>sd_session_get_remote_user()</function>,
313 <function>sd_session_get_remote_host()</function>,
314 <function>sd_session_get_tty()</function>, and
315 <function>sd_session_get_extra_device_access()</function>
316 return 0 or a positive integer. On failure, these calls return a
317 negative errno-style error code.</para>
318
319 <refsect2>
320 <title>Errors</title>
321
322 <para>Returned errors may indicate the following problems:</para>
323
324 <variablelist>
325
326 <varlistentry>
327 <term><constant>-ENXIO</constant></term>
328
329 <listitem><para>The specified session does not exist.</para>
330 </listitem>
331 </varlistentry>
332
333 <varlistentry>
334 <term><constant>-ENODATA</constant></term>
335
336 <listitem><para>The given field is not specified for the described session.</para>
337 </listitem>
338 </varlistentry>
339
340 <varlistentry>
341 <term><constant>-EINVAL</constant></term>
342
343 <listitem><para>An input parameter was invalid (out of range, or <constant>NULL</constant>, where
344 that is not accepted).</para></listitem>
345 </varlistentry>
346
347 <varlistentry>
348 <term><constant>-ENOMEM</constant></term>
349
350 <listitem><para>Memory allocation failed.</para></listitem>
351 </varlistentry>
352 </variablelist>
353 </refsect2>
354 </refsect1>
355
356 <xi:include href="libsystemd-pkgconfig.xml" />
357
358 <refsect1>
359 <title>History</title>
360 <para><function>sd_session_get_state()</function> was added in version 186.</para>
361 <para><function>sd_session_get_tty()</function> was added in version 198.</para>
362 <para><function>sd_session_get_vt()</function> was added in version 207.</para>
363 <para><function>sd_session_is_remote()</function>,
364 <function>sd_session_get_remote_host()</function>, and
365 <function>sd_session_get_remote_user()</function> were added in version 209.</para>
366 <para><function>sd_session_get_desktop()</function> was added in version 217.</para>
367 <para><function>sd_session_get_username()</function>,
368 <function>sd_session_get_start_time()</function>, and
369 <function>sd_session_get_leader()</function> were added in version 254.</para>
370 <para><function>sd_session_get_extra_device_access()</function> was added in version 260.</para>
371 </refsect1>
372
373 <refsect1>
374 <title>See Also</title>
375
376 <para><simplelist type="inline">
377 <member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
378 <member><citerefentry><refentrytitle>sd-login</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
379 <member><citerefentry><refentrytitle>sd_pid_get_session</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
380 </simplelist></para>
381 </refsect1>
382
383 </refentry>