42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek<?xml version='1.0'?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
12b42c76672a66c2d4ea7212c14f8f1b5a62b78dTom Gundersen"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek<!--
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek This file is part of systemd.
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek Copyright 2015 Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek systemd is free software; you can redistribute it and/or modify it
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek under the terms of the GNU Lesser General Public License as published by
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek the Free Software Foundation; either version 2.1 of the License, or
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek (at your option) any later version.
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek systemd is distributed in the hope that it will be useful, but
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek WITHOUT ANY WARRANTY; without even the implied warranty of
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek Lesser General Public License for more details.
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek You should have received a copy of the GNU Lesser General Public License
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek along with systemd; If not, see <http://www.gnu.org/licenses/>.
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek-->
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering<refentry id="sd_event_wait" xmlns:xi="http://www.w3.org/2001/XInclude">
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <refentryinfo>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <title>sd_event_wait</title>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <productname>systemd</productname>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <authorgroup>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <author>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <contrib>Developer</contrib>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <firstname>Tom</firstname>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <surname>Gundersen</surname>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <email>teg@jklm.no</email>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek </author>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek </authorgroup>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek </refentryinfo>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <refmeta>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <refentrytitle>sd_event_wait</refentrytitle>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <manvolnum>3</manvolnum>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek </refmeta>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <refnamediv>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <refname>sd_event_wait</refname>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <refname>sd_event_prepare</refname>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <refname>sd_event_dispatch</refname>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <refname>sd_event_get_state</refname>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <refname>SD_EVENT_INITIAL</refname>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <refname>SD_EVENT_PREPARING</refname>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <refname>SD_EVENT_ARMED</refname>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <refname>SD_EVENT_PENDING</refname>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <refname>SD_EVENT_RUNNING</refname>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <refname>SD_EVENT_EXITING</refname>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <refname>SD_EVENT_FINISHED</refname>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <refpurpose>Low-level event loop operations</refpurpose>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek </refnamediv>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <refsynopsisdiv>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <funcsynopsis>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <funcsynopsisinfo>#include &lt;systemd/sd-event.h&gt;</funcsynopsisinfo>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <funcsynopsisinfo><token>enum</token> {
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <constant>SD_EVENT_INITIAL</constant>,
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <constant>SD_EVENT_PREPARING</constant>,
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <constant>SD_EVENT_ARMED</constant>,
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <constant>SD_EVENT_PENDING</constant>,
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <constant>SD_EVENT_RUNNING</constant>,
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <constant>SD_EVENT_EXITING</constant>,
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <constant>SD_EVENT_FINISHED</constant>,
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering};</funcsynopsisinfo>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <funcprototype>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <funcdef>int <function>sd_event_prepare</function></funcdef>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <paramdef>sd_event *<parameter>event</parameter></paramdef>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek </funcprototype>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <funcprototype>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <funcdef>int <function>sd_event_wait</function></funcdef>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <paramdef>sd_event *<parameter>event</parameter></paramdef>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <paramdef>uint64_t <parameter>usec</parameter></paramdef>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek </funcprototype>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <funcprototype>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <funcdef>int <function>sd_event_dispatch</function></funcdef>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <paramdef>sd_event *<parameter>event</parameter></paramdef>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek </funcprototype>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <funcprototype>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <funcdef>int <function>sd_event_get_state</function></funcdef>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <paramdef>sd_event *<parameter>event</parameter></paramdef>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering </funcprototype>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek </funcsynopsis>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek </refsynopsisdiv>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <refsect1>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <title>Description</title>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <para>The low-level <function>sd_event_prepare()</function>,
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <function>sd_event_wait()</function> and
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <function>sd_event_dispatch()</function> functions may be used to
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering execute specific phases of an event loop. See
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <citerefentry><refentrytitle>sd_event_run</refentrytitle><manvolnum>3</manvolnum></citerefentry>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering and
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <citerefentry><refentrytitle>sd_event_loop</refentrytitle><manvolnum>3</manvolnum></citerefentry>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering for higher-level functions that execute individual but complete
7f3fdb7f19a109fa3d1be92926bfe4cea1817da5Jakub Wilk iterations of an event loop or run it continuously.</para>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <para><function>sd_event_prepare()</function> checks for pending
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek events and arms necessary timers. If any events are ready to be
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering processed ("pending"), it returns a positive, non-zero value, and the caller
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering should process these events with
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <function>sd_event_dispatch()</function>.</para>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <para><function>sd_event_dispatch()</function> dispatches the
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering highest priority event source that has a pending event. On
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering success, <function>sd_event_dispatch()</function> returns either
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering zero, which indicates that no further event sources may be
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering dispatched and exiting of the event loop was requested via
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <citerefentry><refentrytitle>sd_event_exit</refentrytitle><manvolnum>3</manvolnum></citerefentry>;
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering or a positive non-zero value, which means that an event source was
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering dispatched and the loop returned to its initial state, and the
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering caller should initiate the next event loop iteration by invoking
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <function>sd_event_prepare()</function> again.</para>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <para>In case <function>sd_event_prepare()</function> returned
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering zero, <function>sd_event_wait()</function> should be called to
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering wait for further events or a timeout. If any events are ready to
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering be processed, it returns a positive, non-zero value, and the
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering events should be dispatched with
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <function>sd_event_dispatch()</function>. Otherwise, the event
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering loop returned to its initial state and the next event loop
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering iteration should be initiated by invoking
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <function>sd_event_prepare()</function> again.</para>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <para><function>sd_event_get_state()</function> may be used to
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering determine the state the event loop is currently in. It returns one
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering of the states described below.</para>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <para>All four functions take, as the first argument, the event
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering loop object <parameter>event</parameter> that has been created
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering with <function>sd_event_new()</function>. The timeout for
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <function>sd_event_wait()</function> is specified in
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <parameter>usec</parameter> in milliseconds. <constant>(uint64_t)
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering -1</constant> may be used to specify an infinite timeout.</para>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering</refsect1>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <refsect1>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <title>State Machine</title>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <para>The event loop knows the following states, that may be
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering queried with <function>sd_event_get_state()</function>.</para>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <variablelist>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <varlistentry>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <term><constant>SD_EVENT_INITIAL</constant></term>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <listitem><para>The initial state the event loop is in,
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering before each event loop iteration. Use
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <function>sd_event_prepare()</function> to transition the
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering event loop into the <constant>SD_EVENT_ARMED</constant> or
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <constant>SD_EVENT_PENDING</constant> states.</para></listitem>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering </varlistentry>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <varlistentry>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <term><constant>SD_EVENT_PREPARING</constant></term>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <listitem><para>An event source is currently being prepared,
7f3fdb7f19a109fa3d1be92926bfe4cea1817da5Jakub Wilk i.e. the preparation handler is currently being executed, as
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering set with
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <citerefentry><refentrytitle>sd_event_set_prepare</refentrytitle><manvolnum>3</manvolnum></citerefentry>. This
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering state is only seen in the event source preparation handler
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering that is invoked from the
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <function>sd_event_prepare()</function> call and is
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering immediately followed by <constant>SD_EVENT_ARMED</constant> or
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <constant>SD_EVENT_PENDING</constant>.</para></listitem>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering </varlistentry>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <varlistentry>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <term><constant>SD_EVENT_ARMED</constant></term>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <listitem><para><function>sd_event_prepare()</function> has
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering been called and no event sources were ready to be
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering dispatched. Use <function>sd_event_wait()</function> to wait
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering for new events, and transition into
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <constant>SD_EVENT_PENDING</constant> or back into
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <constant>SD_EVENT_INITIAL</constant>.</para></listitem>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering </varlistentry>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <varlistentry>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <term><constant>SD_EVENT_PENDING</constant></term>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <listitem><para><function>sd_event_prepare()</function> or
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <function>sd_event_wait()</function> have been called and
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering there were event sources with events pending. Use
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <function>sd_event_dispatch()</function> to dispatch the
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering highest priority event source and transition back to
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <constant>SD_EVENT_INITIAL</constant>, or
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <constant>SD_EVENT_FINISHED</constant>.</para></listitem>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering </varlistentry>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <varlistentry>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <term><constant>SD_EVENT_RUNNING</constant></term>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <listitem><para>A regular event source is currently being
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering dispatched. This state is only seen in the event source
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering handler that is invoked from the
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <function>sd_event_dispatch()</function> call, and is
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering immediately followed by <constant>SD_EVENT_INITIAL</constant>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering or <constant>SD_EVENT_FINISHED</constant> as soon the event
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering source handler returns. Note that during dispatching of exit
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering event sources the <constant>SD_EVENT_EXITING</constant> state
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering is seen instead.</para></listitem>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering </varlistentry>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <varlistentry>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <term><constant>SD_EVENT_EXITING</constant></term>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <listitem><para>Similar to
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <constant>SD_EVENT_RUNNING</constant> but is the state in
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering effect while dispatching exit event sources. It is followed by
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <constant>SD_EVENT_INITIAL</constant> or
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <constant>SD_EVENT_FINISHED</constant> as soon as the event
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering handler returns.</para></listitem>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering </varlistentry>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <varlistentry>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <term><constant>SD_EVENT_FINISHED</constant></term>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <listitem><para>The event loop has exited. All exit event
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering sources have run. If the event loop is in this state it serves
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering no purpose anymore, and should be freed.</para></listitem>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering </varlistentry>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering </variablelist>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <para>A simplified flow chart of the states and the calls to
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering transition between them is shown below. Note that
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <constant>SD_EVENT_PREPARING</constant>,
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <constant>SD_EVENT_RUNNING</constant> and
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <constant>SD_EVENT_EXITING</constant> are not shown here.</para>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <programlisting>
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering INITIAL -&lt;---&lt;---&lt;---&lt;---&lt;---&lt;---&lt;---&lt;---&lt;---&lt;---&lt;---&lt;---\
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering | |
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering | ^
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering | |
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering v ret == 0 |
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering sd_event_prepare() &gt;---&gt;---&gt;---&gt;---&gt;- ARMED |
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering | | ^
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering | ret > 0 | |
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering | | |
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering v v ret == 0 |
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering PENDING &lt;---&lt;---&lt;---&lt;---&lt;---&lt; sd_event_wait() &gt;---&gt;---&gt;--+
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering | ret > 0 ^
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering | |
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering | |
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering v |
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering sd_event_dispatch() &gt;---&gt;---&gt;---&gt;---&gt;---&gt;---&gt;---&gt;---&gt;---&gt;---&gt;/
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering | ret > 0
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering | ret == 0
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering |
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering v
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering FINISHED
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek </programlisting>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek </refsect1>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <refsect1>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <title>Return Value</title>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <para>On success, these functions return 0 or a positive integer.
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek On failure, they return a negative errno-style error code. In case
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering of <function>sd_event_prepare()</function> and
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <function>sd_event_wait()</function>, a positive, non-zero return
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering code indicates that events are ready to be processed and zero
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering indicates that no events are ready. In case of
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <function>sd_event_dispatch()</function>, a positive, non-zero
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering return code indicates that the event loop returned to its initial
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering state and zero indicates the event loop has
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering exited. <function>sd_event_get_state()</function> returns a
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering positive or zero state on success.</para>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek </refsect1>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <refsect1>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <title>Errors</title>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <para>Returned errors may indicate the following problems:</para>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <variablelist>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <varlistentry>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <term><constant>-EINVAL</constant></term>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
a8eaaee72a2f06e0fb64fb71de3b71ecba31dafbJan Engelhardt <listitem><para>The <parameter>event</parameter> parameter is
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering invalid or <constant>NULL</constant>.</para></listitem>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek </varlistentry>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <varlistentry>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <term><constant>-EBUSY</constant></term>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <listitem><para>The event loop object is not in the right
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek state.</para></listitem>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek </varlistentry>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <varlistentry>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <term><constant>-ESTALE</constant></term>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <listitem><para>The event loop is already terminated.</para></listitem>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek </varlistentry>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <varlistentry>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <term><constant>-ECHILD</constant></term>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <listitem><para>The event loop has been created in a different process.</para></listitem>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek </varlistentry>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek </variablelist>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
b938cb902c3b5bca807a94b277672c64d6767886Jan Engelhardt <para>Other errors are possible, too.</para>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek </refsect1>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <xi:include href="libsystemd-pkgconfig.xml" />
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <refsect1>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <title>See Also</title>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <para>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <citerefentry><refentrytitle>sd_event_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <citerefentry><refentrytitle>sd_event_add_defer</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <citerefentry><refentrytitle>sd_event_add_exit</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <citerefentry><refentrytitle>sd_event_add_post</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <citerefentry><refentrytitle>sd_event_run</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <citerefentry><refentrytitle>sd_event_get_fd</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering <citerefentry><refentrytitle>sd_event_source_set_prepare</refentrytitle><manvolnum>3</manvolnum></citerefentry>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek </para>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek </refsect1>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek</refentry>