]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/sd_event_wait.xml
test-execute: Add tests for new PassEnvironment= directive
[thirdparty/systemd.git] / man / sd_event_wait.xml
1 <?xml version='1.0'?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
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 2015 Zbigniew Jędrzejewski-Szmek
9
10 systemd is free software; you can redistribute it and/or modify it
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
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
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 -->
23
24 <refentry id="sd_event_wait">
25
26 <refentryinfo>
27 <title>sd_event_wait</title>
28 <productname>systemd</productname>
29
30 <authorgroup>
31 <author>
32 <contrib>Developer</contrib>
33 <firstname>Tom</firstname>
34 <surname>Gundersen</surname>
35 <email>teg@jklm.no</email>
36 </author>
37 </authorgroup>
38 </refentryinfo>
39
40 <refmeta>
41 <refentrytitle>sd_event_wait</refentrytitle>
42 <manvolnum>3</manvolnum>
43 </refmeta>
44
45 <refnamediv>
46 <refname>sd_event_wait</refname>
47 <refname>sd_event_prepare</refname>
48 <refname>sd_event_dispatch</refname>
49
50 <refpurpose>Run parts of the libsystemd event loop</refpurpose>
51 </refnamediv>
52
53 <refsynopsisdiv>
54 <funcsynopsis>
55 <funcsynopsisinfo>#include &lt;systemd/sd-event.h&gt;</funcsynopsisinfo>
56
57 <funcprototype>
58 <funcdef>int <function>sd_event_prepare</function></funcdef>
59 <paramdef>sd_event *<parameter>event</parameter></paramdef>
60 </funcprototype>
61
62 <funcprototype>
63 <funcdef>int <function>sd_event_wait</function></funcdef>
64 <paramdef>sd_event *<parameter>event</parameter></paramdef>
65 <paramdef>uint64_t <parameter>timeout</parameter></paramdef>
66 </funcprototype>
67
68 <funcprototype>
69 <funcdef>int <function>sd_event_dispatch</function></funcdef>
70 <paramdef>sd_event *<parameter>event</parameter></paramdef>
71 </funcprototype>
72
73 </funcsynopsis>
74 </refsynopsisdiv>
75
76 <refsect1>
77 <title>Description</title>
78
79 <para>Functions described here form parts of an event loop.</para>
80
81 <para><function>sd_event_prepare</function> checks for pending
82 events and arms necessary timers. If any events are ready to be
83 processed, it returns a positive value, and the events should be
84 processed with <function>sd_event_dispatch</function>.
85 <function>sd_event_dispatch</function> runs a handler for one of
86 the events from the sources with the highest priority. On success,
87 <function>sd_event_dispatch</function> returns either 0, which
88 means that the loop is finished, or a positive value, which means
89 that the loop is again in the initial state and
90 <function>sd_event_prepare</function> should be called again.
91 </para>
92
93 <para>In case <function>sd_event_prepare</function> returned 0,
94 <function>sd_event_wait</function> should be called to wait for
95 events or a timeout. If any events are ready to be processed, it
96 returns a positive value, and the events should be processed with
97 <function>sd_event_dispatch</function>. Otherwise, the loop is
98 back in the initial state and <function>sd_event_prepare</function>
99 should be called again.</para>
100
101 <programlisting>
102 ┌──────────┐
103 │ initial ├──←←←←←←←←←←←←←←←←←←←─┐
104 └───┬──────┘ ↑
105 │ ↑
106 sd_event_prepare ┌─────────┐ ↑
1070 →→→→→→→──┤ armed │ ↑
108 1 └───┬─────┘ ↑
109 ↓ │ ↑
110 ↓ sd_event_wait ↑
111 ├───←←←←←←←─── 1 ┴─ 0 →→→→→→→─┘
112 ┌───┴──────┐ ↑
113 │ pending │ ↑
114 └───┬──────┘ ↑
115 │ ↑
116 sd_event_dispatch ↑
117 ↓ ↑
1181 ──────────→→→→→→→─────────┘
119 0
120
121 ┌───┴──────┐
122 │ finished │
123 └──────────┘
124 </programlisting>
125
126 <para>All three functions take, as the first argument, the event
127 loop object <parameter>event</parameter> that is created with
128 <function>sd_event_new</function>. The timeout for
129 <function>sd_event_wait</function> is specified with
130 <parameter>timeout</parameter> in milliseconds.
131 <constant>(uint64_t) -1</constant> may be used to specify an
132 infinite timeout.</para>
133 </refsect1>
134
135 <refsect1>
136 <title>Return Value</title>
137
138 <para>On success, these functions return 0 or a positive integer.
139 On failure, they return a negative errno-style error code. In case
140 of <function>sd_event_prepare</function> and
141 <function>sd_event_wait</function>, a positive value means that
142 events are ready to be processed and 0 means that no events are
143 ready. In case of <function>sd_event_dispatch</function>, a
144 positive value means that the loop is again in the initial state
145 and 0 means the loop is finished. For any of these functions, a
146 negative return value means the loop must be aborted.</para>
147 </refsect1>
148
149 <refsect1>
150 <title>Errors</title>
151
152 <para>Returned errors may indicate the following problems:</para>
153
154 <variablelist>
155 <varlistentry>
156 <term><constant>-EINVAL</constant></term>
157
158 <listitem><para>The <parameter>event</parameter> parameter is
159 <constant>NULL</constant>.</para></listitem>
160 </varlistentry>
161
162 <varlistentry>
163 <term><constant>-EBUSY</constant></term>
164
165 <listitem><para>The event loop object is not in the right
166 state.</para></listitem>
167 </varlistentry>
168
169 <varlistentry>
170 <term><constant>-ESTALE</constant></term>
171
172 <listitem><para>The event loop is already terminated.</para></listitem>
173
174 </varlistentry>
175
176 <varlistentry>
177 <term><constant>-ECHILD</constant></term>
178
179 <listitem><para>The event loop has been created in a different process.</para></listitem>
180
181 </varlistentry>
182
183 </variablelist>
184
185 <para>Other errors are possible, too.</para>
186 </refsect1>
187
188 <refsect1>
189 <title>Notes</title>
190
191 <para>Functions described here are available
192 as a shared library, which can be compiled and linked to with the
193 <constant>libsystemd</constant> <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
194 file.</para>
195 </refsect1>
196
197 <refsect1>
198 <title>See Also</title>
199
200 <para>
201 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
202 <citerefentry><refentrytitle>sd_event_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
203 <citerefentry><refentrytitle>sd_event_run</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
204 <citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
205 <citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
206 <citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
207 <citerefentry><refentrytitle>sd_event_add_defer</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
208 <citerefentry><refentrytitle>sd_event_add_exit</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
209 <citerefentry><refentrytitle>sd_event_add_post</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
210 </para>
211 </refsect1>
212
213 </refentry>