sd_event_run.xml revision 48f69d8fb4d0cf34d578352572c96d86e13caa79
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"
681eb9cf2b831293a4f3d4c48a748d2e4a25d69eFilipe Brandenburger"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
681eb9cf2b831293a4f3d4c48a748d2e4a25d69eFilipe Brandenburger<!ENTITY % entities SYSTEM "custom-entities.ent" >
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek This file is part of systemd.
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek Copyright 2015 Zbigniew 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 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 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 <productname>systemd</productname>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <refentrytitle>sd_event_run</refentrytitle>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <refname>sd_event_loop</refname>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <refpurpose>Run libsystemd event loop</refpurpose>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <refsynopsisdiv>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <funcsynopsisinfo>#include <systemd/sd-event.h></funcsynopsisinfo>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <funcdef>int <function>sd_event_run</function></funcdef>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <paramdef>sd_event *<parameter>event</parameter></paramdef>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <paramdef>uint64_t <parameter>timeout</parameter></paramdef>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek </funcprototype>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <funcdef>int <function>sd_event_loop</function></funcdef>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <paramdef>sd_event *<parameter>event</parameter></paramdef>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek </funcprototype>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek </refsynopsisdiv>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <para><function>sd_event_run()</function> can be used to run one
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek iteration of the event loop of libsystemd. This function waits
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek until an event to process is available and dispatches a handler
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek for it. Parameter <parameter>timeout</parameter> specifices the
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek maximum time (in microseconds) to wait. <constant>(uint64_t)
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek -1</constant> may be used to specify an infinite timeout.</para>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <para><function>sd_event_loop</function> runs
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <function>sd_event_wait</function> in a loop with a timeout of
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek infinity. This makes it suitable for the main event loop of a
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <para>The event loop object <parameter>event</parameter> is
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <function>sd_event_new</function>.
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek Events to wait for and their handlers can be registered with
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <function>sd_event_add_time</function>,
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <function>sd_event_add_child</function>,
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <function>sd_event_add_signal</function>,
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <function>sd_event_add_defer</function>,
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <function>sd_event_add_exit</function>,
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <function>sd_event_add_post</function>.
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <para>For more fine-grained control,
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <function>sd_event_prepare</function>,
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <function>sd_event_wait</function>, and
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <function>sd_event_dispatch</function> may be used. Along with
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <function>sd_event_get_fd</function>, those functions make it
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek possible to integrate the libsystemd loop inside of another event
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.
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <function>sd_event_run</function> returns 0 if the event loop is
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek finished, and a positive value if it can be continued.</para>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <para>Returned errors may indicate the following problems:</para>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <term><constant>-EINVAL</constant></term>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <listitem><para>Parameter <parameter>event</parameter> is
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <constant>NULL</constant>.</para></listitem>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <term><constant>-EBUSY</constant></term>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <listitem><para>The event loop object is not in the right
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <citerefentry><refentrytitle>sd_event_prepare</refentrytitle><manvolnum>3</manvolnum></citerefentry>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek for an explanation of possible states).</para></listitem>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <term><constant>-ESTALE</constant></term>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <listitem><para>The event loop is already terminated.</para></listitem>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <term><constant>-ECHILD</constant></term>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <listitem><para>The event loop has been created in a different process.</para></listitem>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <para>Other errors are possible too.</para>
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <para><function>sd_event_run()</function> and
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <function>sd_event_loop()</function> are available
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek as a shared library, which can be compiled and linked to with the
42f1ab5009eed71f0d4f83681b8fdbed8664fca3Zbigniew Jędrzejewski-Szmek <constant>libsystemd</constant> <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
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_wait</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>,
c268628a20e684d6079de6e5da96c10429e6ed1eZbigniew Jędrzejewski-Szmek <citerefentry><refentrytitle>sd_event_add_post</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
c268628a20e684d6079de6e5da96c10429e6ed1eZbigniew Jędrzejewski-Szmek <ulink url="https://developer.gnome.org/glib/unstable/glib-The-Main-Event-Loop.html">GLIb Main Event Loop</ulink>.