1
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>sd_session_is_active</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><style>
11
background-color: #c60f0f;
15
h1:hover > a.headerlink, h2:hover > a.headerlink, h3:hover > a.headerlink, dt:hover > a.headerlink {
18
</style><a href="index.html">Index </a>·
19
<a href="systemd.directives.html">Directives </a>·
20
<a href="../python-systemd/index.html">Python </a>·
21
<a href="../libudev/index.html">libudev </a>·
22
<a href="../libudev/index.html">gudev </a><span style="float:right">systemd 204</span><hr><div class="refentry"><a name="sd_session_is_active"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>sd_session_is_active, sd_session_get_state, sd_session_get_uid, sd_session_get_seat, sd_session_get_service, sd_session_get_type, sd_session_get_class, sd_session_get_display, sd_session_get_tty — Determine state of a specific session</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include <systemd/sd-login.h></pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_session_is_active</b>(</code></td><td>const char* <var class="pdparam">session</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_session_get_state</b>(</code></td><td>const char* <var class="pdparam">session</var>, </td></tr><tr><td> </td><td>char** <var class="pdparam">state</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_session_get_uid</b>(</code></td><td>const char* <var class="pdparam">session</var>, </td></tr><tr><td> </td><td>uid_t* <var class="pdparam">uid</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_session_get_seat</b>(</code></td><td>const char* <var class="pdparam">session</var>, </td></tr><tr><td> </td><td>char** <var class="pdparam">seat</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_session_get_service</b>(</code></td><td>const char* <var class="pdparam">session</var>, </td></tr><tr><td> </td><td>char** <var class="pdparam">service</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_session_get_type</b>(</code></td><td>const char* <var class="pdparam">session</var>, </td></tr><tr><td> </td><td>char** <var class="pdparam">type</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_session_get_class</b>(</code></td><td>const char* <var class="pdparam">session</var>, </td></tr><tr><td> </td><td>char** <var class="pdparam">class</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_session_get_display</b>(</code></td><td>const char* <var class="pdparam">session</var>, </td></tr><tr><td> </td><td>char** <var class="pdparam">display</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_session_get_tty</b>(</code></td><td>const char* <var class="pdparam">session</var>, </td></tr><tr><td> </td><td>char** <var class="pdparam">tty</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a name="idm259799547264"></a><h2 id="Description">Description<a class="headerlink" title="Permalink to this headline" href="#Description">¶</a></h2><p><code class="function">sd_session_is_active()</code> may
23
be used to determine whether the session identified by
24
the specified session identifier is currently active
25
(i.e. currently in the foreground and available for
26
user input) or not.</p><p><code class="function">sd_session_get_state()</code> may
27
be used to determine the state of the session
28
identified by the specified session identifier. The
29
following states are currently known:
30
<code class="literal">online</code> (session logged in, but
31
session not active, i.e. not in the foreground),
32
<code class="literal">active</code> (session logged in and
33
active, i.e. in the foreground),
34
<code class="literal">closing</code> (session nominally logged
35
out, but some processes belonging to it are still
36
around). In the future additional states might be
37
defined, client code should be written to be robust in
38
regards to additional state strings being
39
returned. This function is a more generic version of
40
<code class="function">sd_session_is_active()</code>. The returned
41
string needs to be freed with the libc
42
<a href="free.html"><span class="citerefentry"><span class="refentrytitle">free</span>(3)</span></a>
43
call after use.</p><p><code class="function">sd_session_get_uid()</code> may be
44
used to determine the user identifier of the Unix user the session
45
identified by the specified session identifier belongs
46
to.</p><p><code class="function">sd_session_get_seat()</code> may
47
be used to determine the seat identifier of the seat
48
the session identified by the specified session
49
identifier belongs to. Note that not all sessions are
50
attached to a seat, this call will fail for them. The
51
returned string needs to be freed with the libc
52
<a href="free.html"><span class="citerefentry"><span class="refentrytitle">free</span>(3)</span></a>
53
call after use.</p><p><code class="function">sd_session_get_service()</code>
54
may be used to determine the name of the service (as
55
passed during PAM session setup) that registered the
56
session identified by the specified session
57
identifier. The returned string needs to be freed with
59
<a href="free.html"><span class="citerefentry"><span class="refentrytitle">free</span>(3)</span></a>
60
call after use.</p><p><code class="function">sd_session_get_type()</code> may
61
be used to determine the type of the session
62
identified by the specified session identifier. The
63
returned string is one of <code class="literal">x11</code>,
64
<code class="literal">tty</code> or
65
<code class="literal">unspecified</code> and needs to be freed
67
<a href="free.html"><span class="citerefentry"><span class="refentrytitle">free</span>(3)</span></a>
68
call after use.</p><p><code class="function">sd_session_get_class()</code> may
69
be used to determine the class of the session
70
identified by the specified session identifier. The
71
returned string is one of <code class="literal">user</code>,
72
<code class="literal">greeter</code>,
73
<code class="literal">lock-screen</code>, or
74
<code class="literal">background</code> and needs to be freed
76
<a href="free.html"><span class="citerefentry"><span class="refentrytitle">free</span>(3)</span></a>
77
call after use.</p><p><code class="function">sd_session_get_display()</code>
78
may be used to determine the X11 display of the
79
session identified by the specified session
80
identifier. The returned string needs to be
82
<a href="free.html"><span class="citerefentry"><span class="refentrytitle">free</span>(3)</span></a>
83
call after use.</p><p><code class="function">sd_session_get_tty()</code>
84
may be used to determine the TTY device of the
85
session identified by the specified session
86
identifier. The returned string needs to be
88
<a href="free.html"><span class="citerefentry"><span class="refentrytitle">free</span>(3)</span></a>
89
call after use.</p><p>If the <code class="literal">session</code> parameter of
90
any of these functions is passed as NULL the operation
91
is executed for the session the calling process is a
92
member of, if there is any.</p></div><div class="refsect1"><a name="idm259799512752"></a><h2 id="Return Value">Return Value<a class="headerlink" title="Permalink to this headline" href="#Return%20Value">¶</a></h2><p>If the test succeeds
93
<code class="function">sd_session_is_active()</code> returns a
94
positive integer, if it fails 0. On success
95
<code class="function">sd_session_get_state()</code>,
96
<code class="function">sd_session_get_uid()</code>,
97
<code class="function">sd_session_get_seat()</code>,
98
<code class="function">sd_session_get_service()</code>,
99
<code class="function">sd_session_get_type()</code>,
100
<code class="function">sd_session_get_class()</code>,
101
<code class="function">sd_session_get_display()</code> and
102
<code class="function">sd_session_get_tty()</code> return 0 or
103
a positive integer. On failure, these calls return a
104
negative errno-style error code.</p></div><div class="refsect1"><a name="idm259794878944"></a><h2 id="Notes">Notes<a class="headerlink" title="Permalink to this headline" href="#Notes">¶</a></h2><p>The <code class="function">sd_session_is_active()</code>,
105
<code class="function">sd_session_get_state()</code>,
106
<code class="function">sd_session_get_uid()</code>,
107
<code class="function">sd_session_get_seat()</code>,
108
<code class="function">sd_session_get_service()</code>,
109
<code class="function">sd_session_get_type()</code>,
110
<code class="function">sd_session_get_class()</code>,
111
<code class="function">sd_session_get_display()</code> and
112
<code class="function">sd_session_get_tty()</code>
113
interfaces are available as shared library, which can
114
be compiled and linked to with the
115
<code class="literal">libsystemd-login</code>
116
<a href="pkg-config.html"><span class="citerefentry"><span class="refentrytitle">pkg-config</span>(1)</span></a>
117
file.</p></div><div class="refsect1"><a name="idm259794870624"></a><h2 id="See Also">See Also<a class="headerlink" title="Permalink to this headline" href="#See%20Also">¶</a></h2><p>
118
<a href="systemd.html"><span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span></a>,
119
<a href="sd-login.html"><span class="citerefentry"><span class="refentrytitle">sd-login</span>(3)</span></a>,
120
<a href="sd_pid_get_session.html"><span class="citerefentry"><span class="refentrytitle">sd_pid_get_session</span>(3)</span></a>
121
</p></div></div></body></html>