]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/sd_event_add_time.xml
copy: only check for traversing mount points on directories
[thirdparty/systemd.git] / man / sd_event_add_time.xml
CommitLineData
3802a3d3 1<?xml version='1.0'?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
b408026b 2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
12b42c76 3"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
b408026b
LP
4
5<!--
572eb058
ZJS
6 SPDX-License-Identifier: LGPL-2.1+
7
b975b0d5 8 This file is part of systemd.
b408026b 9
b975b0d5 10 Copyright 2014 Lennart Poettering
b408026b
LP
11-->
12
dc83f27a 13<refentry id="sd_event_add_time" xmlns:xi="http://www.w3.org/2001/XInclude">
b408026b
LP
14
15 <refentryinfo>
16 <title>sd_event_add_time</title>
17 <productname>systemd</productname>
18
19 <authorgroup>
20 <author>
21 <contrib>Developer</contrib>
22 <firstname>Lennart</firstname>
23 <surname>Poettering</surname>
24 <email>lennart@poettering.net</email>
25 </author>
26 </authorgroup>
27 </refentryinfo>
28
29 <refmeta>
30 <refentrytitle>sd_event_add_time</refentrytitle>
31 <manvolnum>3</manvolnum>
32 </refmeta>
33
34 <refnamediv>
35 <refname>sd_event_add_time</refname>
36 <refname>sd_event_source_get_time</refname>
37 <refname>sd_event_source_set_time</refname>
38 <refname>sd_event_source_get_time_accuracy</refname>
39 <refname>sd_event_source_set_time_accuracy</refname>
40 <refname>sd_event_source_get_time_clock</refname>
dc83f27a 41 <refname>sd_event_time_handler_t</refname>
b408026b
LP
42
43 <refpurpose>Add a timer event source to an event loop</refpurpose>
44 </refnamediv>
45
46 <refsynopsisdiv>
47 <funcsynopsis>
dc83f27a
LP
48 <funcsynopsisinfo>#include &lt;systemd/sd-event.h&gt;</funcsynopsisinfo>
49
50 <funcsynopsisinfo><token>typedef</token> struct sd_event_source sd_event_source;</funcsynopsisinfo>
51
52 <funcprototype>
53 <funcdef>typedef int (*<function>sd_event_time_handler_t</function>)</funcdef>
54 <paramdef>sd_event_source *<parameter>s</parameter></paramdef>
55 <paramdef>uint64_t <parameter>usec</parameter></paramdef>
56 <paramdef>void *<parameter>userdata</parameter></paramdef>
57 </funcprototype>
b408026b
LP
58
59 <funcprototype>
60 <funcdef>int <function>sd_event_add_time</function></funcdef>
61 <paramdef>sd_event *<parameter>event</parameter></paramdef>
62 <paramdef>sd_event_source **<parameter>source</parameter></paramdef>
63 <paramdef>clockid_t <parameter>clock</parameter></paramdef>
64 <paramdef>uint64_t <parameter>usec</parameter></paramdef>
65 <paramdef>uint64_t <parameter>accuracy</parameter></paramdef>
66 <paramdef>sd_event_time_handler_t <parameter>handler</parameter></paramdef>
3b3d7d06 67 <paramdef>void *<parameter>userdata</parameter></paramdef>
b408026b
LP
68 </funcprototype>
69
70 <funcprototype>
71 <funcdef>int <function>sd_event_source_get_time</function></funcdef>
72 <paramdef>sd_event_source *<parameter>source</parameter></paramdef>
dc83f27a 73 <paramdef>uint64_t *<parameter>usec</parameter></paramdef>
b408026b
LP
74 </funcprototype>
75
76 <funcprototype>
77 <funcdef>int <function>sd_event_source_set_time</function></funcdef>
78 <paramdef>sd_event_source *<parameter>source</parameter></paramdef>
dc83f27a 79 <paramdef>uint64_t <parameter>usec</parameter></paramdef>
b408026b
LP
80 </funcprototype>
81
82 <funcprototype>
83 <funcdef>int <function>sd_event_source_get_time_accuracy</function></funcdef>
84 <paramdef>sd_event_source *<parameter>source</parameter></paramdef>
dc83f27a 85 <paramdef>uint64_t *<parameter>usec</parameter></paramdef>
b408026b
LP
86 </funcprototype>
87
88 <funcprototype>
89 <funcdef>int <function>sd_event_source_set_time_accuracy</function></funcdef>
90 <paramdef>sd_event_source *<parameter>source</parameter></paramdef>
dc83f27a 91 <paramdef>uint64_t <parameter>usec</parameter></paramdef>
b408026b
LP
92 </funcprototype>
93
94 <funcprototype>
95 <funcdef>int <function>sd_event_source_get_time_clock</function></funcdef>
96 <paramdef>sd_event_source *<parameter>source</parameter></paramdef>
97 <paramdef>clockid_t *<parameter>clock</parameter></paramdef>
98 </funcprototype>
99
100 </funcsynopsis>
101 </refsynopsisdiv>
102
103 <refsect1>
104 <title>Description</title>
105
393003e1
LP
106 <para><function>sd_event_add_time()</function> adds a new timer event source to an event loop. The event loop
107 object is specified in the <parameter>event</parameter> parameter, the event source object is returned in the
108 <parameter>source</parameter> parameter. The <parameter>clock</parameter> parameter takes a clock identifier, one
109 of <constant>CLOCK_REALTIME</constant>, <constant>CLOCK_MONOTONIC</constant>, <constant>CLOCK_BOOTTIME</constant>,
110 <constant>CLOCK_REALTIME_ALARM</constant>, or <constant>CLOCK_BOOTTIME_ALARM</constant>. See
111 <citerefentry><refentrytitle>timerfd_create</refentrytitle><manvolnum>2</manvolnum></citerefentry> for details
112 regarding the various types of clocks. The <parameter>usec</parameter> parameter specifies the earliest time, in
113 microseconds (µs), relative to the clock's epoch, when the timer shall be triggered. If a time already in the past
114 is specified (including <constant>0</constant>), this timer source "fires" immediately and is ready to be
595bfe7d 115 dispatched. If the parameter is specified as <constant>UINT64_MAX</constant> the timer event will never elapse,
393003e1
LP
116 which may be used as an alternative to explicitly disabling a timer event source with
117 <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>. The
118 <parameter>accuracy</parameter> parameter specifies an additional accuracy value in µs specifying how much the
119 timer event may be delayed. Use <constant>0</constant> to select the default accuracy (250ms). Use 1µs for maximum
120 accuracy. Consider specifying 60000000µs (1min) or larger for long-running events that may be delayed
121 substantially. Picking higher accuracy values allows the system to coalesce timer events more aggressively,
122 improving power efficiency. The <parameter>handler</parameter> parameter shall reference a function to call when
123 the timer elapses. The handler function will be passed the <parameter>userdata</parameter> pointer, which may be
124 chosen freely by the caller. The handler is also passed the configured trigger time, even if it is actually called
125 slightly later, subject to the specified accuracy value, the kernel timer slack (see
126 <citerefentry><refentrytitle>prctl</refentrytitle><manvolnum>2</manvolnum></citerefentry>), and additional
127 scheduling latencies. To query the actual time the handler was called use
dc83f27a 128 <citerefentry><refentrytitle>sd_event_now</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
3144ebca
ZJS
129
130 <para>By default, the timer will elapse once
131 (<constant>SD_EVENT_ONESHOT</constant>), but this may be changed
132 with
133 <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
134 If the handler function returns a negative error code, it will be
dc83f27a
LP
135 disabled after the invocation, even if the
136 <constant>SD_EVENT_ON</constant> mode was requested before. Note
137 that a timer event set to <constant>SD_EVENT_ON</constant> will
7f3fdb7f 138 fire continuously unless its configured time is updated using
dc83f27a 139 <function>sd_event_source_set_time()</function>.
b408026b
LP
140 </para>
141
dc83f27a
LP
142 <para>To destroy an event source object use
143 <citerefentry><refentrytitle>sd_event_source_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
144 but note that the event source is only removed from the event loop
145 when all references to the event source are dropped. To make sure
f23e83b1
ZJS
146 an event source does not fire anymore, even if it is still referenced,
147 disable the event source using
148 <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>
149 with <constant>SD_EVENT_OFF</constant>.</para>
dc83f27a 150
7f3fdb7f 151 <para>If the second parameter of
f23e83b1
ZJS
152 <function>sd_event_add_time()</function> is
153 <constant>NULL</constant> no reference to the event source object
154 is returned. In this case the event source is considered
155 "floating", and will be destroyed implicitly when the event loop
156 itself is destroyed.</para>
dc83f27a
LP
157
158 <para>If the <parameter>handler</parameter> to
f23e83b1
ZJS
159 <function>sd_event_add_time()</function> is
160 <constant>NULL</constant>, and the event source fires, this will
161 be considered a request to exit the event loop. In this case, the
162 <parameter>userdata</parameter> parameter, cast to an integer, is
163 used for the exit code passed to
dc83f27a
LP
164 <citerefentry><refentrytitle>sd_event_exit</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
165
166 <para>Use <constant>CLOCK_BOOTTIME_ALARM</constant> and
167 <constant>CLOCK_REALTIME_ALARM</constant> to define event sources
168 that may wake up the system from suspend.</para>
169
170 <para>In order to set up relative timers (that is, relative to the
171 current time), retrieve the current time via
172 <citerefentry><refentrytitle>sd_event_now</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
f23e83b1 173 add the desired timespan to it, and use the result as
dc83f27a
LP
174 the <parameter>usec</parameter> parameter to
175 <function>sd_event_add_time()</function>.</para>
176
177 <para>In order to set up repetitive timers (that is, timers that
178 are triggered in regular intervals), set up the timer normally,
179 for the first invocation. Each time the event handler is invoked,
180 update the timer's trigger time with
181 <citerefentry><refentrytitle>sd_event_source_set_time</refentrytitle><manvolnum>3</manvolnum></citerefentry> for the next timer
182 iteration, and reenable the timer using
183 <function>sd_event_source_set_enabled()</function>. To calculate
184 the next point in time to pass to
185 <function>sd_event_source_set_time()</function>, either use as
186 base the <parameter>usec</parameter> parameter passed to the timer
187 callback, or the timestamp returned by
188 <function>sd_event_now()</function>. In the former case timer
189 events will be regular, while in the latter case the scheduling
190 latency will keep accumulating on the timer.</para>
191
b408026b 192 <para><function>sd_event_source_get_time()</function> retrieves
f23e83b1 193 the configured time value of an event source created
b408026b
LP
194 previously with <function>sd_event_add_time()</function>. It takes
195 the event source object and a pointer to a variable to store the
f23e83b1 196 time in, relative to the selected clock's epoch, in µs.</para>
b408026b
LP
197
198 <para><function>sd_event_source_set_time()</function> changes the
f23e83b1
ZJS
199 time of an event source created previously with
200 <function>sd_event_add_time()</function>. It takes the event
201 source object and a time relative to the selected clock's epoch,
202 in µs.</para>
b408026b
LP
203
204 <para><function>sd_event_source_get_time_accuracy()</function>
037a3ded 205 retrieves the configured accuracy value of an event source
b408026b
LP
206 created previously with <function>sd_event_add_time()</function>. It
207 takes the event source object and a pointer to a variable to store
f23e83b1 208 the accuracy in. The accuracy is specified in µs.</para>
b408026b
LP
209
210 <para><function>sd_event_source_set_time_accuracy()</function>
211 changes the configured accuracy of a timer event source created
212 previously with <function>sd_event_add_time()</function>. It takes
f23e83b1 213 the event source object and accuracy, in µs.</para>
b408026b
LP
214
215 <para><function>sd_event_source_get_time_clock()</function>
037a3ded 216 retrieves the configured clock of an event source created
b408026b
LP
217 previously with <function>sd_event_add_time()</function>. It takes
218 the event source object and a pointer to a variable to store the
219 clock identifier in.</para>
b408026b
LP
220 </refsect1>
221
222 <refsect1>
223 <title>Return Value</title>
224
225 <para>On success, these functions return 0 or a positive
226 integer. On failure, they return a negative errno-style error
227 code. </para>
228 </refsect1>
229
230 <refsect1>
231 <title>Errors</title>
232
f23e83b1 233 <para>Returned values may indicate the following problems:</para>
b408026b
LP
234
235 <variablelist>
236 <varlistentry>
8474b70c 237 <term><constant>-ENOMEM</constant></term>
b408026b 238
3144ebca 239 <listitem><para>Not enough memory to allocate an object.</para></listitem>
b408026b
LP
240 </varlistentry>
241
242 <varlistentry>
8474b70c 243 <term><constant>-EINVAL</constant></term>
b408026b
LP
244
245 <listitem><para>An invalid argument has been passed.</para></listitem>
246
247 </varlistentry>
248
249 <varlistentry>
8474b70c 250 <term><constant>-ESTALE</constant></term>
b408026b
LP
251
252 <listitem><para>The event loop is already terminated.</para></listitem>
253
254 </varlistentry>
255
256 <varlistentry>
8474b70c 257 <term><constant>-ECHILD</constant></term>
b408026b
LP
258
259 <listitem><para>The event loop has been created in a different process.</para></listitem>
260
261 </varlistentry>
262
263 <varlistentry>
15411c0c 264 <term><constant>-EOPNOTSUPP</constant></term>
b408026b
LP
265
266 <listitem><para>The selected clock is not supported by the event loop implementation.</para></listitem>
267
268 </varlistentry>
b408026b 269
dc83f27a
LP
270 <varlistentry>
271 <term><constant>-EDOM</constant></term>
b408026b 272
dc83f27a
LP
273 <listitem><para>The passed event source is not a timer event source.</para></listitem>
274 </varlistentry>
275 </variablelist>
b408026b
LP
276 </refsect1>
277
dc83f27a
LP
278 <xi:include href="libsystemd-pkgconfig.xml" />
279
b408026b
LP
280 <refsect1>
281 <title>See Also</title>
282
283 <para>
284 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
285 <citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
286 <citerefentry><refentrytitle>sd_event_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
dc83f27a
LP
287 <citerefentry><refentrytitle>sd_event_now</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
288 <citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
3144ebca 289 <citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
edf25737 290 <citerefentry><refentrytitle>sd_event_add_child</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
1eb54dc6 291 <citerefentry><refentrytitle>sd_event_add_inotify</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
4dfefc19 292 <citerefentry><refentrytitle>sd_event_add_defer</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
dc83f27a
LP
293 <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
294 <citerefentry><refentrytitle>sd_event_source_set_priority</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
295 <citerefentry><refentrytitle>sd_event_source_set_userdata</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
296 <citerefentry><refentrytitle>sd_event_source_set_description</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
297 <citerefentry project='man-pages'><refentrytitle>clock_gettime</refentrytitle><manvolnum>2</manvolnum></citerefentry>,
298 <citerefentry project='man-pages'><refentrytitle>timerfd_create</refentrytitle><manvolnum>2</manvolnum></citerefentry>,
299 <citerefentry project='man-pages'><refentrytitle>prctl</refentrytitle><manvolnum>2</manvolnum></citerefentry>
b408026b
LP
300 </para>
301 </refsect1>
302
303</refentry>