1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
6 This file is part of elogind.
8 Copyright 2010 Lennart Poettering
10 elogind is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
15 elogind is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public License
21 along with elogind; If not, see <http://www.gnu.org/licenses/>.
24 <refentry id="sd_session_is_active" conditional='HAVE_PAM'>
27 <title>sd_session_is_active</title>
28 <productname>elogind</productname>
32 <contrib>Developer</contrib>
33 <firstname>Lennart</firstname>
34 <surname>Poettering</surname>
35 <email>lennart@poettering.net</email>
41 <refentrytitle>sd_session_is_active</refentrytitle>
42 <manvolnum>3</manvolnum>
46 <refname>sd_session_is_active</refname>
47 <refname>sd_session_is_remote</refname>
48 <refname>sd_session_get_state</refname>
49 <refname>sd_session_get_uid</refname>
50 <refname>sd_session_get_seat</refname>
51 <refname>sd_session_get_service</refname>
52 <refname>sd_session_get_type</refname>
53 <refname>sd_session_get_class</refname>
54 <refname>sd_session_get_desktop</refname>
55 <refname>sd_session_get_display</refname>
56 <refname>sd_session_get_tty</refname>
57 <refname>sd_session_get_vt</refname>
58 <refname>sd_session_get_remote_host</refname>
59 <refname>sd_session_get_remote_user</refname>
60 <refpurpose>Determine state of a specific session</refpurpose>
65 <funcsynopsisinfo>#include <elogind/sd-login.h></funcsynopsisinfo>
68 <funcdef>int <function>sd_session_is_active</function></funcdef>
69 <paramdef>const char *<parameter>session</parameter></paramdef>
73 <funcdef>int <function>sd_session_is_remote</function></funcdef>
74 <paramdef>const char *<parameter>session</parameter></paramdef>
78 <funcdef>int <function>sd_session_get_state</function></funcdef>
79 <paramdef>const char *<parameter>session</parameter></paramdef>
80 <paramdef>char **<parameter>state</parameter></paramdef>
84 <funcdef>int <function>sd_session_get_uid</function></funcdef>
85 <paramdef>const char *<parameter>session</parameter></paramdef>
86 <paramdef>uid_t *<parameter>uid</parameter></paramdef>
90 <funcdef>int <function>sd_session_get_seat</function></funcdef>
91 <paramdef>const char *<parameter>session</parameter></paramdef>
92 <paramdef>char **<parameter>seat</parameter></paramdef>
96 <funcdef>int <function>sd_session_get_service</function></funcdef>
97 <paramdef>const char *<parameter>session</parameter></paramdef>
98 <paramdef>char **<parameter>service</parameter></paramdef>
102 <funcdef>int <function>sd_session_get_type</function></funcdef>
103 <paramdef>const char *<parameter>session</parameter></paramdef>
104 <paramdef>char **<parameter>type</parameter></paramdef>
108 <funcdef>int <function>sd_session_get_class</function></funcdef>
109 <paramdef>const char *<parameter>session</parameter></paramdef>
110 <paramdef>char **<parameter>class</parameter></paramdef>
114 <funcdef>int <function>sd_session_get_desktop</function></funcdef>
115 <paramdef>const char *<parameter>session</parameter></paramdef>
116 <paramdef>char **<parameter>desktop</parameter></paramdef>
120 <funcdef>int <function>sd_session_get_display</function></funcdef>
121 <paramdef>const char *<parameter>session</parameter></paramdef>
122 <paramdef>char **<parameter>display</parameter></paramdef>
126 <funcdef>int <function>sd_session_get_remote_host</function></funcdef>
127 <paramdef>const char *<parameter>session</parameter></paramdef>
128 <paramdef>char **<parameter>remote_host</parameter></paramdef>
132 <funcdef>int <function>sd_session_get_remote_user</function></funcdef>
133 <paramdef>const char *<parameter>session</parameter></paramdef>
134 <paramdef>char **<parameter>remote_user</parameter></paramdef>
138 <funcdef>int <function>sd_session_get_tty</function></funcdef>
139 <paramdef>const char *<parameter>session</parameter></paramdef>
140 <paramdef>char **<parameter>tty</parameter></paramdef>
144 <funcdef>int <function>sd_session_get_vt</function></funcdef>
145 <paramdef>const char *<parameter>session</parameter></paramdef>
146 <paramdef>unsigned int *<parameter>vt</parameter></paramdef>
152 <title>Description</title>
154 <para><function>sd_session_is_active()</function> may be used to
155 determine whether the session identified by the specified session
156 identifier is currently active (i.e. currently in the foreground
157 and available for user input) or not.</para>
159 <para><function>sd_session_is_remote()</function> may be used to
160 determine whether the session identified by the specified session
161 identifier is a remote session (i.e. its remote host is known) or
164 <para><function>sd_session_get_state()</function> may be used to
165 determine the state of the session identified by the specified
166 session identifier. The following states are currently known:
167 <literal>online</literal> (session logged in, but session not
168 active, i.e. not in the foreground), <literal>active</literal>
169 (session logged in and active, i.e. in the foreground),
170 <literal>closing</literal> (session nominally logged out, but some
171 processes belonging to it are still around). In the future
172 additional states might be defined, client code should be written
173 to be robust in regards to additional state strings being
174 returned. This function is a more generic version of
175 <function>sd_session_is_active()</function>. The returned string
176 needs to be freed with the libc
177 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
178 call after use.</para>
180 <para><function>sd_session_get_uid()</function> may be used to
181 determine the user identifier of the Unix user the session
182 identified by the specified session identifier belongs to.</para>
184 <para><function>sd_session_get_seat()</function> may be used to
185 determine the seat identifier of the seat the session identified
186 by the specified session identifier belongs to. Note that not all
187 sessions are attached to a seat, this call will fail (returning
188 <constant>-ENODATA</constant>) for them. The returned string needs
189 to be freed with the libc
190 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
191 call after use.</para>
193 <para><function>sd_session_get_service()</function> may be used to
194 determine the name of the service (as passed during PAM session
195 setup) that registered the session identified by the specified
196 session identifier. The returned string needs to be freed with the
198 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
199 call after use.</para>
201 <para><function>sd_session_get_type()</function> may be used to
202 determine the type of the session identified by the specified
203 session identifier. The returned string is one of
204 <literal>x11</literal>, <literal>wayland</literal>,
205 <literal>tty</literal>, <literal>mir</literal> or
206 <literal>unspecified</literal> and needs to be freed with the libc
207 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
208 call after use.</para>
210 <para><function>sd_session_get_class()</function> may be used to
211 determine the class of the session identified by the specified
212 session identifier. The returned string is one of
213 <literal>user</literal>, <literal>greeter</literal>,
214 <literal>lock-screen</literal>, or <literal>background</literal>
215 and needs to be freed with the libc
216 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
217 call after use.</para>
219 <para><function>sd_session_get_desktop()</function> may be used to
220 determine the brand of the desktop running on the session
221 identified by the specified session identifier. This field can be
222 set freely by desktop environments and does not follow any special
223 formatting. However, desktops are strongly recommended to use the
224 same identifiers and capitalization as for
225 <varname>$XDG_CURRENT_DESKTOP</varname>, as defined by the <ulink
226 url="http://standards.freedesktop.org/desktop-entry-spec/latest/">Desktop
227 Entry Specification</ulink>. The returned string needs to be freed
229 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
230 call after use.</para>
232 <para><function>sd_session_get_display()</function> may be used to
233 determine the X11 display of the session identified by the
234 specified session identifier. The returned string needs to be
236 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
237 call after use.</para>
239 <para><function>sd_session_get_remote_host()</function> may be
240 used to determine the remote hostname of the session identified by
241 the specified session identifier. The returned string needs to be
243 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
244 call after use.</para>
246 <para><function>sd_session_get_remote_user()</function> may be
247 used to determine the remote username of the session identified by
248 the specified session identifier. The returned string needs to be
250 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
251 call after use. Note that this value is rarely known to the
252 system, and even then should not be relied on.</para>
254 <para><function>sd_session_get_tty()</function> may be used to
255 determine the TTY device of the session identified by the
256 specified session identifier. The returned string needs to be
258 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
259 call after use.</para>
261 <para><function>sd_session_get_vt()</function> may be used to
262 determine the VT number of the session identified by the specified
263 session identifier. This function will return an error if the seat
264 does not support VTs.</para>
266 <para>If the <varname>session</varname> parameter of any of these
267 functions is passed as <constant>NULL</constant>, the operation is
268 executed for the session the calling process is a member of, if
273 <title>Return Value</title>
275 <para>If the test succeeds,
276 <function>sd_session_is_active()</function> and
277 <function>sd_session_is_remote()</function> return a
278 positive integer; if it fails, 0. On success,
279 <function>sd_session_get_state()</function>,
280 <function>sd_session_get_uid()</function>,
281 <function>sd_session_get_seat()</function>,
282 <function>sd_session_get_service()</function>,
283 <function>sd_session_get_type()</function>,
284 <function>sd_session_get_class()</function>,
285 <function>sd_session_get_display()</function>,
286 <function>sd_session_get_remote_user()</function>,
287 <function>sd_session_get_remote_host()</function> and
288 <function>sd_session_get_tty()</function> return 0 or
289 a positive integer. On failure, these calls return a
290 negative errno-style error code.</para>
294 <title>Errors</title>
296 <para>Returned errors may indicate the following problems:</para>
301 <term><constant>-ENXIO</constant></term>
303 <listitem><para>The specified session does not exist.</para>
308 <term><constant>-ENODATA</constant></term>
310 <listitem><para>The given field is not specified for the described
316 <term><constant>-EINVAL</constant></term>
318 <listitem><para>An input parameter was invalid (out of range,
319 or NULL, where that is not accepted).</para></listitem>
323 <term><constant>-ENOMEM</constant></term>
325 <listitem><para>Memory allocation failed.</para></listitem>
333 <para>The <function>sd_session_is_active()</function>,
334 <function>sd_session_get_state()</function>,
335 <function>sd_session_get_uid()</function>,
336 <function>sd_session_get_seat()</function>,
337 <function>sd_session_get_service()</function>,
338 <function>sd_session_get_type()</function>,
339 <function>sd_session_get_class()</function>,
340 <function>sd_session_get_display()</function>,
341 <function>sd_session_get_remote_host()</function>,
342 <function>sd_session_get_remote_user()</function> and
343 <function>sd_session_get_tty()</function>
344 interfaces are available as a shared library, which can
345 be compiled and linked to with the
346 <constant>libelogind</constant> <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
351 <title>See Also</title>
354 <citerefentry><refentrytitle>elogind</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
355 <citerefentry><refentrytitle>sd-login</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
356 <citerefentry><refentrytitle>sd_pid_get_session</refentrytitle><manvolnum>3</manvolnum></citerefentry>