1
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>sd_login_monitor_new</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_login_monitor_new"><a name="sd_login_monitor_new"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>sd_login_monitor_new, sd_login_monitor_unref, sd_login_monitor_flush, sd_login_monitor_get_fd — Monitor login sessions, seats and users</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_login_monitor_new</b>(</code></td><td>const char* <var class="pdparam">category</var>, </td></tr><tr><td> </td><td>sd_login_monitor** <var class="pdparam">ret</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">sd_login_monitor* <b class="fsfunc">sd_login_monitor_unref</b>(</code></td><td>sd_login_monitor* <var class="pdparam">m</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_login_monitor_flush</b>(</code></td><td>sd_login_monitor* <var class="pdparam">m</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_login_monitor_get_fd</b>(</code></td><td>sd_login_monitor* <var class="pdparam">m</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1" title="Description"><a name="id508740"></a><h2>Description</h2><p><code class="function">sd_login_monitor_new()</code> may
2
be used to monitor login session, users and seats. Via
3
a monitor object a file descriptor can be integrated
4
into an application defined event loop which is woken
5
up each time a user logs in, logs out or a seat is
6
added or removed, or a session, user, or seat changes
7
state otherwise. The first parameter takes a string
8
which can be either <code class="literal">seat</code> (to get
9
only notifications about seats being added, removed or
10
changed), <code class="literal">session</code> (to get only
11
notifications about sessions being created or removed
12
or changed) or <code class="literal">uid</code> (to get only
13
notifications when a user changes state in respect to
14
logins). If notifications shall be generated in all
15
these conditions, NULL may be passed. Note that in
16
future additional categories may be defined. The
17
second parameter returns a monitor object and needs to
19
<code class="function">sd_login_monitor_unref()</code> call
20
after use.</p><p><code class="function">sd_login_monitor_unref()</code>
21
may be used to destroy a monitor object. Note that
22
this will invalidate any file descriptor returned by
23
<code class="function">sd_login_monitor_get_fd()</code>.</p><p><code class="function">sd_login_monitor_flush()</code>
24
may be used to reset the wakeup state of the monitor
25
object. Whenever an event causes the monitor to wake
26
up the event loop via the file descriptor this
27
function needs to be called to reset the wake-up
28
state. If this call is not invoked the file descriptor
29
will immediately wake up the event loop again.</p><p><code class="function">sd_login_monitor_get_fd()</code>
30
may be used to retrieve the file descriptor of the
31
monitor object that may be integrated in an
32
application defined event loop, based around
33
<span class="citerefentry"><span class="refentrytitle">poll</span>(2)</span>
34
or a similar interface. The application should include
35
the returned file descriptor as wake up source for
36
POLLIN events. Whenever a wake-up is triggered the
37
file descriptor needs to be reset via
38
<code class="function">sd_login_monitor_flush()</code>. An
39
application needs to reread the login state with a
41
<span class="citerefentry"><span class="refentrytitle">sd_get_seats</span>(3)</span>
42
or similar to determine what changed.</p></div><div class="refsect1" title="Return Value"><a name="id476246"></a><h2>Return Value</h2><p>On success
43
<code class="function">sd_login_monitor_new()</code> and
44
<code class="function">sd_login_monitor_flush()</code> return 0
45
or a positive integer. On success
46
<code class="function">sd_login_monitor_get_fd()</code> returns
47
a Unix file descriptor. On failure, these calls return
48
a negative errno-style error code.</p><p><code class="function">sd_login_monitor_unref()</code>
49
always returns NULL.</p></div><div class="refsect1" title="Notes"><a name="id476284"></a><h2>Notes</h2><p>The <code class="function">sd_login_monitor_new()</code>,
50
<code class="function">sd_login_monitor_unref()</code>, <code class="function">sd_login_monitor_flush()</code> and
51
<code class="function">sd_login_monitor_get_fd()</code> interfaces
52
are available as shared library, which can be compiled
53
and linked to with the
54
<code class="literal">libsystemd-login</code>
55
<span class="citerefentry"><span class="refentrytitle">pkg-config</span>(1)</span>
56
file.</p></div><div class="refsect1" title="See Also"><a name="id476393"></a><h2>See Also</h2><p>
57
<span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span>,
58
<span class="citerefentry"><span class="refentrytitle">sd-login</span>(7)</span>,
59
<span class="citerefentry"><span class="refentrytitle">sd_get_seats</span>(3)</span>
60
</p></div></div></body></html>