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.76.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" title="sd_session_is_active"><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_uid, sd_session_get_seat, sd_session_get_service, sd_session_get_type, sd_session_get_class, sd_session_get_display — Determine state of a specific session</p></div><div class="refsynopsisdiv" title="Synopsis"><h2>Synopsis</h2><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include <systemd/sd-login.h></pre><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" class="funcprototype-table"><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" summary="Function synopsis" cellspacing="0" cellpadding="0" class="funcprototype-table"><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" summary="Function synopsis" cellspacing="0" cellpadding="0" class="funcprototype-table"><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" summary="Function synopsis" cellspacing="0" cellpadding="0" class="funcprototype-table"><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" summary="Function synopsis" cellspacing="0" cellpadding="0" class="funcprototype-table"><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" summary="Function synopsis" cellspacing="0" cellpadding="0" class="funcprototype-table"><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" summary="Function synopsis" cellspacing="0" cellpadding="0" class="funcprototype-table"><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></div></div><div class="refsect1" title="Description"><a name="id384022"></a><h2>Description</h2><p><code class="function">sd_session_is_active()</code> may
2
be used to determine whether the session identified by
3
the specified session identifier is currently active
4
(i.e. currently in the foreground and available for
5
user input) or not.</p><p><code class="function">sd_session_get_uid()</code> may be
6
used to determine the user identifier of the Unix user the session
7
identified by the specified session identifier belongs
8
to.</p><p><code class="function">sd_session_get_seat()</code> may
9
be used to determine the seat identifier of the seat
10
the session identified by the specified session
11
identifier belongs to. Note that not all sessions are
12
attached to a seat, this call will fail for them. The
13
returned string needs to be freed with the libc
14
<span class="citerefentry"><span class="refentrytitle">free</span>(3)</span>
15
call after use.</p><p><code class="function">sd_session_get_service()</code>
16
may be used to determine the name of the service (as
17
passed during PAM session setup) that registered the
18
session identified by the specified session
19
identifier. The returned string needs to be freed with
21
<span class="citerefentry"><span class="refentrytitle">free</span>(3)</span>
22
call after use.</p><p><code class="function">sd_session_get_type()</code> may
23
be used to determine the type of the session
24
identified by the specified session identifier. The
25
returned string is one of <code class="literal">x11</code>,
26
<code class="literal">tty</code> or
27
<code class="literal">unspecified</code> and needs to be freed
29
<span class="citerefentry"><span class="refentrytitle">free</span>(3)</span>
30
call after use.</p><p><code class="function">sd_session_get_class()</code> may
31
be used to determine the class of the session
32
identified by the specified session identifier. The
33
returned string is one of <code class="literal">user</code>,
34
<code class="literal">greeter</code> or
35
<code class="literal">lock-screen</code> and needs to be freed
37
<span class="citerefentry"><span class="refentrytitle">free</span>(3)</span>
38
call after use.</p><p><code class="function">sd_session_get_display()</code>
39
may be used to determine the X11 display of the
40
session identified by the specified session
41
identifier. The returned string is one of needs to be
43
<span class="citerefentry"><span class="refentrytitle">free</span>(3)</span>
44
call after use.</p><p>If the <code class="literal">session</code> parameter of
45
any of these functions is passed as NULL the operation
46
is executed for the session the calling process is a
47
member of, if there is any.</p></div><div class="refsect1" title="Return Value"><a name="id384239"></a><h2>Return Value</h2><p>If the test succeeds
48
<code class="function">sd_session_is_active()</code> returns a
49
positive integer, if it fails 0. On success
50
<code class="function">sd_session_get_uid()</code>,
51
<code class="function">sd_session_get_service()</code> and
52
<code class="function">sd_session_get_seat()</code> return 0 or
53
a positive integer. On failure, these calls return a
54
negative errno-style error code.</p></div><div class="refsect1" title="Notes"><a name="id384275"></a><h2>Notes</h2><p>The <code class="function">sd_session_is_active()</code>,
55
<code class="function">sd_session_get_uid()</code>,
56
<code class="function">sd_session_get_service()</code> and
57
<code class="function">sd_session_get_seat()</code> interfaces
58
are available as shared library, which can be compiled
59
and linked to with the
60
<code class="literal">libsystemd-login</code>
61
<span class="citerefentry"><span class="refentrytitle">pkg-config</span>(1)</span>
62
file.</p></div><div class="refsect1" title="See Also"><a name="id384324"></a><h2>See Also</h2><p>
63
<span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span>,
64
<span class="citerefentry"><span class="refentrytitle">sd-login</span>(7)</span>,
65
<span class="citerefentry"><span class="refentrytitle">sd_pid_get_session</span>(3)</span>
66
</p></div></div></body></html>