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 systemd.
8 Copyright 2010 Lennart Poettering
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 systemd 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 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 <refentry id="sd_session_is_active">
27 <title>sd_session_is_active</title>
28 <productname>systemd</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_get_uid</refname>
48 <refname>sd_session_get_seat</refname>
49 <refname>sd_session_get_service</refname>
50 <refpurpose>Determine state of a specific session</refpurpose>
55 <funcsynopsisinfo>#include <systemd/sd-login.h></funcsynopsisinfo>
58 <funcdef>int <function>sd_session_is_active</function></funcdef>
59 <paramdef>const char* <parameter>session</parameter></paramdef>
63 <funcdef>int <function>sd_session_get_uid</function></funcdef>
64 <paramdef>const char* <parameter>session</parameter></paramdef>
65 <paramdef>uid_t* <parameter>uid</parameter></paramdef>
69 <funcdef>int <function>sd_session_get_seat</function></funcdef>
70 <paramdef>const char* <parameter>session</parameter></paramdef>
71 <paramdef>char** <parameter>seat</parameter></paramdef>
75 <funcdef>int <function>sd_session_get_service</function></funcdef>
76 <paramdef>const char* <parameter>session</parameter></paramdef>
77 <paramdef>char** <parameter>service</parameter></paramdef>
83 <title>Description</title>
85 <para><function>sd_session_is_active()</function> may
86 be used to determine whether the session identified by
87 the specified session identifier is currently active
88 (i.e. currently in the foreground and available for
89 user input) or not.</para>
91 <para><function>sd_session_get_uid()</function> may be
92 used to determine the user identifier of the Unix user the session
93 identified by the specified session identifier belongs
96 <para><function>sd_session_get_seat()</function> may
97 be used to determine the seat identifier of the seat
98 the session identified by the specified session
99 identifier belongs to. Note that not all sessions are
100 attached to a seat, this call will fail for them. The
101 returned string needs to be freed with the libc
102 <citerefentry><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
103 call after use.</para>
105 <para><function>sd_session_get_service()</function>
106 may be used to determine the name of the service (as
107 passed during PAM session setup) that registered the
108 session identified by the specified session
109 identifier. The returned string needs to be freed with
111 <citerefentry><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
112 call after use.</para>
116 <title>Return Value</title>
118 <para>If the test succeeds
119 <function>sd_session_is_active()</function> returns a
120 positive integer, if it fails 0. On success
121 <function>sd_session_get_uid()</function>,
122 <function>sd_session_get_service()</function> and
123 <function>sd_session_get_seat()</function> return 0 or
124 a positive integer. On failure, these calls return a
125 negative errno-style error code.</para>
131 <para>The <function>sd_session_is_active()</function>,
132 <function>sd_session_get_uid()</function>,
133 <function>sd_session_get_service()</function> and
134 <function>sd_session_get_seat()</function> interfaces
135 are available as shared library, which can be compiled
136 and linked to with the
137 <literal>libsystemd-login</literal>
138 <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
143 <title>See Also</title>
146 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
147 <citerefentry><refentrytitle>sd-login</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
148 <citerefentry><refentrytitle>sd_pid_get_session</refentrytitle><manvolnum>3</manvolnum></citerefentry>