]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/sd_login_monitor_new.xml
man: wording and grammar updates
[thirdparty/systemd.git] / man / sd_login_monitor_new.xml
CommitLineData
0b3b020a
LP
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">
4
5<!--
6 This file is part of systemd.
7
8 Copyright 2010 Lennart Poettering
9
10 systemd is free software; you can redistribute it and/or modify it
5430f7f2
LP
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
0b3b020a
LP
13 (at your option) any later version.
14
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
5430f7f2 18 Lesser General Public License for more details.
0b3b020a 19
5430f7f2 20 You should have received a copy of the GNU Lesser General Public License
0b3b020a
LP
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22-->
23
56ba3c78 24<refentry id="sd_login_monitor_new" conditional='HAVE_PAM'>
0b3b020a
LP
25
26 <refentryinfo>
27 <title>sd_login_monitor_new</title>
28 <productname>systemd</productname>
29
30 <authorgroup>
31 <author>
32 <contrib>Developer</contrib>
33 <firstname>Lennart</firstname>
34 <surname>Poettering</surname>
35 <email>lennart@poettering.net</email>
36 </author>
37 </authorgroup>
38 </refentryinfo>
39
40 <refmeta>
41 <refentrytitle>sd_login_monitor_new</refentrytitle>
42 <manvolnum>3</manvolnum>
43 </refmeta>
44
45 <refnamediv>
46 <refname>sd_login_monitor_new</refname>
47 <refname>sd_login_monitor_unref</refname>
48 <refname>sd_login_monitor_flush</refname>
49 <refname>sd_login_monitor_get_fd</refname>
dace83cb 50 <refname>sd_login_monitor_get_events</refname>
667c24a6 51 <refname>sd_login_monitor_get_timeout</refname>
976c46f8 52 <refname>sd_login_monitor</refname>
e10375f2 53 <refpurpose>Monitor login sessions, seats, users and virtual machines/containers</refpurpose>
0b3b020a
LP
54 </refnamediv>
55
56 <refsynopsisdiv>
57 <funcsynopsis>
58 <funcsynopsisinfo>#include &lt;systemd/sd-login.h&gt;</funcsynopsisinfo>
59
60 <funcprototype>
61 <funcdef>int <function>sd_login_monitor_new</function></funcdef>
62 <paramdef>const char* <parameter>category</parameter></paramdef>
63 <paramdef>sd_login_monitor** <parameter>ret</parameter></paramdef>
64 </funcprototype>
65
66 <funcprototype>
67 <funcdef>sd_login_monitor* <function>sd_login_monitor_unref</function></funcdef>
68 <paramdef>sd_login_monitor* <parameter>m</parameter></paramdef>
69 </funcprototype>
70
71 <funcprototype>
72 <funcdef>int <function>sd_login_monitor_flush</function></funcdef>
73 <paramdef>sd_login_monitor* <parameter>m</parameter></paramdef>
74 </funcprototype>
75
76 <funcprototype>
77 <funcdef>int <function>sd_login_monitor_get_fd</function></funcdef>
78 <paramdef>sd_login_monitor* <parameter>m</parameter></paramdef>
79 </funcprototype>
80
dace83cb
LP
81 <funcprototype>
82 <funcdef>int <function>sd_login_monitor_get_events</function></funcdef>
83 <paramdef>sd_login_monitor* <parameter>m</parameter></paramdef>
84 </funcprototype>
85
667c24a6
LP
86 <funcprototype>
87 <funcdef>int <function>sd_login_monitor_get_timeout</function></funcdef>
88 <paramdef>sd_login_monitor* <parameter>m</parameter></paramdef>
89 <paramdef>uint64_t* <parameter>timeout_usec</parameter></paramdef>
90 </funcprototype>
91
0b3b020a
LP
92 </funcsynopsis>
93 </refsynopsisdiv>
94
95 <refsect1>
96 <title>Description</title>
97
98 <para><function>sd_login_monitor_new()</function> may
7ecec470 99 be used to monitor login sessions, users, seats, and
e10375f2
LP
100 virtual machines/containers. Via a monitor object a
101 file descriptor can be integrated into an application
102 defined event loop which is woken up each time a user
103 logs in, logs out or a seat is added or removed, or a
104 session, user, seat or virtual machine/container
105 changes state otherwise. The first parameter takes a
106 string which can be <literal>seat</literal> (to get
0b3b020a
LP
107 only notifications about seats being added, removed or
108 changed), <literal>session</literal> (to get only
109 notifications about sessions being created or removed
e10375f2 110 or changed), <literal>uid</literal> (to get only
0b3b020a 111 notifications when a user changes state in respect to
e10375f2
LP
112 logins) or <literal>machine</literal> (to get only
113 notifications when a virtual machine or container is
114 started or stopped). If notifications shall be
74d00578 115 generated in all these conditions, <constant>NULL</constant> may be
e10375f2
LP
116 passed. Note that in the future additional categories
117 may be defined. The second parameter returns a monitor
118 object and needs to be freed with the
0b3b020a
LP
119 <function>sd_login_monitor_unref()</function> call
120 after use.</para>
121
122 <para><function>sd_login_monitor_unref()</function>
123 may be used to destroy a monitor object. Note that
124 this will invalidate any file descriptor returned by
125 <function>sd_login_monitor_get_fd()</function>.</para>
126
127 <para><function>sd_login_monitor_flush()</function>
128 may be used to reset the wakeup state of the monitor
129 object. Whenever an event causes the monitor to wake
130 up the event loop via the file descriptor this
131 function needs to be called to reset the wake-up
79640424 132 state. If this call is not invoked, the file descriptor
0b3b020a
LP
133 will immediately wake up the event loop again.</para>
134
135 <para><function>sd_login_monitor_get_fd()</function>
136 may be used to retrieve the file descriptor of the
137 monitor object that may be integrated in an
138 application defined event loop, based around
139 <citerefentry><refentrytitle>poll</refentrytitle><manvolnum>2</manvolnum></citerefentry>
140 or a similar interface. The application should include
dace83cb
LP
141 the returned file descriptor as wake-up source for the
142 events mask returned by
667c24a6
LP
143 <function>sd_login_monitor_get_events()</function>. It
144 should pass a timeout value as returned by
145 <function>sd_login_monitor_get_timeout()</function>. Whenever
dace83cb
LP
146 a wake-up is triggered the file descriptor needs to be
147 reset via
0b3b020a
LP
148 <function>sd_login_monitor_flush()</function>. An
149 application needs to reread the login state with a
150 function like
151 <citerefentry><refentrytitle>sd_get_seats</refentrytitle><manvolnum>3</manvolnum></citerefentry>
152 or similar to determine what changed.</para>
dace83cb
LP
153
154 <para><function>sd_login_monitor_get_events()</function>
155 will return the <function>poll()</function> mask to
156 wait for. This function will return a combination of
74d00578 157 <constant>POLLIN</constant>, <constant>POLLOUT</constant>
dace83cb 158 and similar to fill into the
74d00578
ZJS
159 <literal>.events</literal> field of <varname>struct
160 pollfd</varname>.</para>
667c24a6
LP
161
162 <para><function>sd_login_monitor_get_timeout()</function>
163 will return a timeout value for usage in
164 <function>poll()</function>. This returns a value in
74d00578
ZJS
165 microseconds since the epoch of <constant>CLOCK_MONOTONIC</constant>
166 for timing out <function>poll()</function> in
167 <varname>timeout_usec</varname>. See
667c24a6
LP
168 <citerefentry><refentrytitle>clock_gettime</refentrytitle><manvolnum>2</manvolnum></citerefentry>
169 for details about
79640424 170 <constant>CLOCK_MONOTONIC</constant>. If there is no
667c24a6 171 timeout to wait for this will fill in
74d00578 172 <constant>(uint64_t) -1</constant> instead. Note that
667c24a6
LP
173 <function>poll()</function> takes a relative timeout
174 in milliseconds rather than an absolute timeout in
175 microseconds. To convert the absolute 'us' timeout into
176 relative 'ms', use code like the following:</para>
177
178 <programlisting>uint64_t t;
179int msec;
180sd_login_monitor_get_timeout(m, &amp;t);
181if (t == (uint64_t) -1)
182 msec = -1;
183else {
184 struct timespec ts;
185 uint64_t n;
186 clock_getttime(CLOCK_MONOTONIC, &amp;ts);
187 n = (uint64_t) ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
188 msec = t > n ? (int) ((t - n + 999) / 1000) : 0;
189}</programlisting>
190
191 <para>The code above does not do any error checking
74d00578 192 for brevity's sake. The calculated <varname>msec</varname>
667c24a6
LP
193 integer can be passed directly as
194 <function>poll()</function>'s timeout
195 parameter.</para>
0b3b020a
LP
196 </refsect1>
197
198 <refsect1>
199 <title>Return Value</title>
200
201 <para>On success
667c24a6
LP
202 <function>sd_login_monitor_new()</function>,
203 <function>sd_login_monitor_flush()</function> and
204 <function>sd_login_monitor_get_timeout()</function>
205 return 0 or a positive integer. On success
0b3b020a 206 <function>sd_login_monitor_get_fd()</function> returns
dace83cb
LP
207 a Unix file descriptor. On success
208 <function>sd_login_monitor_get_events()</function>
74d00578
ZJS
209 returns a combination of <constant>POLLIN</constant>,
210 <constant>POLLOUT</constant> and suchlike. On failure,
dace83cb
LP
211 these calls return a negative errno-style error
212 code.</para>
0b3b020a
LP
213
214 <para><function>sd_login_monitor_unref()</function>
74d00578 215 always returns <constant>NULL</constant>.</para>
0b3b020a
LP
216 </refsect1>
217
218 <refsect1>
219 <title>Notes</title>
220
221 <para>The <function>sd_login_monitor_new()</function>,
dace83cb
LP
222 <function>sd_login_monitor_unref()</function>,
223 <function>sd_login_monitor_flush()</function>,
667c24a6
LP
224 <function>sd_login_monitor_get_fd()</function>,
225 <function>sd_login_monitor_get_events()</function> and
226 <function>sd_login_monitor_get_timeout()</function>
dace83cb
LP
227 interfaces are available as shared library, which can
228 be compiled and linked to with the
1e158d27 229 <constant>libsystemd-login</constant> <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
0b3b020a
LP
230 file.</para>
231 </refsect1>
232
233 <refsect1>
234 <title>See Also</title>
235
236 <para>
237 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
cb07866b 238 <citerefentry><refentrytitle>sd-login</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
dace83cb 239 <citerefentry><refentrytitle>sd_get_seats</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
667c24a6
LP
240 <citerefentry><refentrytitle>poll</refentrytitle><manvolnum>2</manvolnum></citerefentry>,
241 <citerefentry><refentrytitle>clock_gettime</refentrytitle><manvolnum>2</manvolnum></citerefentry>
0b3b020a
LP
242 </para>
243 </refsect1>
244
245</refentry>