1
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>sd_uid_get_state</title><meta name="generator" content="DocBook XSL Stylesheets V1.77.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><a href="index.html">Index </a>·
2
<a href="systemd.directives.html">Directives </a>·
3
<a href="../python-systemd/index.html">Python </a>·
4
<a href="../libudev/index.html">libudev </a>·
5
<a href="../libudev/index.html">gudev </a><span style="float:right">systemd 202</span><hr><div class="refentry"><a name="sd_uid_get_state"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>sd_uid_get_state, sd_uid_is_on_seat, sd_uid_get_sessions, sd_uid_get_seats — Determine login state of a specific Unix user ID</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_uid_get_state</b>(</code></td><td>uid_t <var class="pdparam">uid</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_uid_is_on_seat</b>(</code></td><td>uid_t <var class="pdparam">uid</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">require_active</var>, </td></tr><tr><td> </td><td>const 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_uid_get_sessions</b>(</code></td><td>uid_t <var class="pdparam">uid</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">require_active</var>, </td></tr><tr><td> </td><td>char*** <var class="pdparam">sessions</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_uid_get_seats</b>(</code></td><td>uid_t <var class="pdparam">uid</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">require_active</var>, </td></tr><tr><td> </td><td>char*** <var class="pdparam">seats</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a name="idp26160"></a><h2>Description</h2><p><code class="function">sd_uid_get_state()</code> may be
6
used to determine the login state of a specific Unix
7
user identifier. The following states are currently
8
known: <code class="literal">offline</code> (user not logged in
9
at all), <code class="literal">lingering</code> (user not logged
10
in, but some user services running),
11
<code class="literal">online</code> (user logged in, but not
12
active, i.e. has no session in the foreground),
13
<code class="literal">active</code> (user logged in, and has at
14
least one active session, i.e. one session in the
15
foreground), <code class="literal">closing</code> (user not
16
logged in, and not lingering, but some processes are
17
still around). In the future additional states might
18
be defined, client code should be written to be robust
19
in regards to additional state strings being
20
returned. The returned string needs to be freed with
22
<a href="free.html"><span class="citerefentry"><span class="refentrytitle">free</span>(3)</span></a>
23
call after use.</p><p><code class="function">sd_uid_is_on_seat()</code> may be
24
used to determine whether a specific user is logged in
25
or active on a specific seat. Accepts a Unix user
26
identifier and a seat identifier string as
27
parameters. The <em class="parameter"><code>require_active</code></em>
28
parameter is a boolean value. If non-zero (true) this
29
function will test if the user is active (i.e. has a
30
session that is in the foreground and accepting user
31
input) on the specified seat, otherwise (false) only
32
if the user is logged in (and possibly inactive) on
33
the specified seat.</p><p><code class="function">sd_uid_get_sessions()</code> may
34
be used to determine the current sessions of the
35
specified user. Accepts a Unix user identifier as
36
parameter. The <em class="parameter"><code>require_active</code></em>
37
parameter controls whether the returned list shall
38
consist of only those sessions where the user is
39
currently active (> 0), where the user is currently
40
online but possibly inactive (= 0), or
41
logged in at all but possibly closing the session (< 0). The call returns a
42
NULL terminated string array of session identifiers in
43
<em class="parameter"><code>sessions</code></em> which needs to be
44
freed by the caller with the libc
45
<a href="free.html"><span class="citerefentry"><span class="refentrytitle">free</span>(3)</span></a>
46
call after use, including all the strings
47
referenced. If the string array parameter is passed as
48
NULL the array will not be filled in, but the return
49
code still indicates the number of current
50
sessions. Note that instead of an empty array NULL may
51
be returned and should be considered equivalent to an
52
empty array.</p><p>Similar, <code class="function">sd_uid_get_seats()</code>
53
may be used to determine the list of seats on which
54
the user currently has sessions. Similar semantics
55
apply, however note that the user may have
56
multiple sessions on the same seat as well as sessions
57
with no attached seat and hence the number of entries
58
in the returned array may differ from the one returned
59
by <code class="function">sd_uid_get_sessions()</code>.</p></div><div class="refsect1"><a name="idp49552"></a><h2>Return Value</h2><p>On success
60
<code class="function">sd_uid_get_state()</code> returns 0 or a
61
positive integer. If the test succeeds
62
<code class="function">sd_uid_is_on_seat()</code> returns a
63
positive integer, if it fails
64
0. <code class="function">sd_uid_get_sessions()</code> and
65
<code class="function">sd_uid_get_seats()</code> return the
66
number of entries in the returned arrays. On failure,
67
these calls return a negative errno-style error
68
code.</p></div><div class="refsect1"><a name="idp53744"></a><h2>Notes</h2><p>The <code class="function">sd_uid_get_state()</code>,
69
<code class="function">sd_uid_is_on_seat()</code>,
70
<code class="function">sd_uid_get_sessions()</code>, and
71
<code class="function">sd_uid_get_seats()</code> interfaces are
72
available as shared library, which can be compiled and
73
linked to with the <code class="literal">libsystemd-login</code>
74
<a href="pkg-config.html"><span class="citerefentry"><span class="refentrytitle">pkg-config</span>(1)</span></a>
75
file.</p></div><div class="refsect1"><a name="idp59520"></a><h2>See Also</h2><p>
76
<a href="systemd.html"><span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span></a>,
77
<a href="sd-login.html"><span class="citerefentry"><span class="refentrytitle">sd-login</span>(3)</span></a>,
78
<a href="sd_pid_get_owner_uid.html"><span class="citerefentry"><span class="refentrytitle">sd_pid_get_owner_uid</span>(3)</span></a>
79
</p></div></div></body></html>