| 1 |
<?xml version='1.0'?> |
| 2 |
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
| 3 |
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> |
| 4 |
<!-- SPDX-License-Identifier: LGPL-2.1-or-later --> |
| 5 |
|
| 6 |
<refentry id="sd_event_exit" xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 7 |
|
| 8 |
<refentryinfo> |
| 9 |
<title>sd_event_exit</title> |
| 10 |
<productname>systemd</productname> |
| 11 |
</refentryinfo> |
| 12 |
|
| 13 |
<refmeta> |
| 14 |
<refentrytitle>sd_event_exit</refentrytitle> |
| 15 |
<manvolnum>3</manvolnum> |
| 16 |
</refmeta> |
| 17 |
|
| 18 |
<refnamediv> |
| 19 |
<refname>sd_event_exit</refname> |
| 20 |
<refname>sd_event_get_exit_code</refname> |
| 21 |
|
| 22 |
<refpurpose>Ask the event loop to exit</refpurpose> |
| 23 |
</refnamediv> |
| 24 |
|
| 25 |
<refsynopsisdiv> |
| 26 |
<funcsynopsis> |
| 27 |
<funcsynopsisinfo>#include <systemd/sd-event.h></funcsynopsisinfo> |
| 28 |
|
| 29 |
<funcprototype> |
| 30 |
<funcdef>int <function>sd_event_exit</function></funcdef> |
| 31 |
<paramdef>sd_event *<parameter>event</parameter></paramdef> |
| 32 |
<paramdef>int <parameter>code</parameter></paramdef> |
| 33 |
</funcprototype> |
| 34 |
|
| 35 |
<funcprototype> |
| 36 |
<funcdef>int <function>sd_event_get_exit_code</function></funcdef> |
| 37 |
<paramdef>sd_event *<parameter>event</parameter></paramdef> |
| 38 |
<paramdef>int *<parameter>ret</parameter></paramdef> |
| 39 |
</funcprototype> |
| 40 |
|
| 41 |
</funcsynopsis> |
| 42 |
</refsynopsisdiv> |
| 43 |
|
| 44 |
<refsect1> |
| 45 |
<title>Description</title> |
| 46 |
|
| 47 |
<para><function>sd_event_exit()</function> requests the event loop |
| 48 |
specified in the <parameter>event</parameter> event loop object to |
| 49 |
exit. The <parameter>code</parameter> parameter may be any integer |
| 50 |
value and is returned as-is by |
| 51 |
<citerefentry><refentrytitle>sd_event_loop</refentrytitle><manvolnum>3</manvolnum></citerefentry> |
| 52 |
after the last event loop iteration. It may also be queried |
| 53 |
using <function>sd_event_get_exit_code()</function>, see |
| 54 |
below. </para> |
| 55 |
|
| 56 |
<para>When exiting is requested the event loop will stop listening |
| 57 |
for and dispatching regular event sources. Instead it will proceed |
| 58 |
with executing only event sources registered with |
| 59 |
<citerefentry><refentrytitle>sd_event_add_exit</refentrytitle><manvolnum>3</manvolnum></citerefentry> |
| 60 |
in the order defined by their priority. After all exit event |
| 61 |
sources have been dispatched the event loop is terminated.</para> |
| 62 |
|
| 63 |
<para>If <function>sd_event_exit()</function> is invoked a second |
| 64 |
time while the event loop is still processing exit event sources, |
| 65 |
the exit code stored in the event loop object is updated, but |
| 66 |
otherwise no further operation is executed.</para> |
| 67 |
|
| 68 |
<para><function>sd_event_get_exit_code()</function> may be used to query the exit code passed to an |
| 69 |
earlier call of <function>sd_event_exit()</function>. The return parameter <parameter>ret</parameter> |
| 70 |
may be set to <constant>NULL</constant>, in order to simply check if <function>sd_event_exit()</function> |
| 71 |
has been called before (as <function>sd_event_get_exit_code()</function> fails with |
| 72 |
<constant>-ENODATA</constant> if that's not the case, see below).</para> |
| 73 |
|
| 74 |
<para>While the full positive and negative integer ranges may be used |
| 75 |
for the exit code, care should be taken not pick exit codes that |
| 76 |
conflict with regular exit codes returned by |
| 77 |
<function>sd_event_loop()</function>, if these exit codes shall be |
| 78 |
distinguishable.</para> |
| 79 |
|
| 80 |
<para>Note that for most event source types passing the callback pointer as <constant>NULL</constant> in |
| 81 |
the respective constructor call (i.e. in |
| 82 |
<citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
| 83 |
<citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
| 84 |
…) has the effect of <function>sd_event_exit()</function> being invoked once the event source triggers, |
| 85 |
with the specified userdata pointer cast to an integer as the exit code parameter. This is useful to |
| 86 |
automatically terminate an event loop after some condition, such as a timeout or reception of |
| 87 |
<constant>SIGTERM</constant> or similar. See the documentation for the respective constructor call for |
| 88 |
details.</para> |
| 89 |
</refsect1> |
| 90 |
|
| 91 |
<refsect1> |
| 92 |
<title>Return Value</title> |
| 93 |
|
| 94 |
<para>On success, <function>sd_event_exit()</function> and <function>sd_event_get_exit_code()</function> |
| 95 |
return 0 or a positive integer. On failure, they return a negative errno-style error code.</para> |
| 96 |
|
| 97 |
<refsect2> |
| 98 |
<title>Errors</title> |
| 99 |
|
| 100 |
<para>Returned errors may indicate the following problems:</para> |
| 101 |
|
| 102 |
<variablelist> |
| 103 |
|
| 104 |
<varlistentry> |
| 105 |
<term><constant>-EINVAL</constant></term> |
| 106 |
|
| 107 |
<listitem><para>The event loop object or error code pointer are invalid.</para></listitem> |
| 108 |
|
| 109 |
</varlistentry> |
| 110 |
|
| 111 |
<varlistentry> |
| 112 |
<term><constant>-ECHILD</constant></term> |
| 113 |
|
| 114 |
<listitem><para>The event loop was created in a different process, library or module instance.</para></listitem> |
| 115 |
</varlistentry> |
| 116 |
|
| 117 |
<varlistentry> |
| 118 |
<term><constant>-ESTALE</constant></term> |
| 119 |
|
| 120 |
<listitem><para>The event loop has exited already and all exit handlers are already processed. |
| 121 |
</para></listitem> |
| 122 |
</varlistentry> |
| 123 |
|
| 124 |
<varlistentry> |
| 125 |
<term><constant>-ENODATA</constant></term> |
| 126 |
|
| 127 |
<listitem><para>Returned by <function>sd_event_get_exit_code()</function> in case the event loop has not |
| 128 |
been requested to exit yet.</para></listitem> |
| 129 |
</varlistentry> |
| 130 |
|
| 131 |
</variablelist> |
| 132 |
</refsect2> |
| 133 |
</refsect1> |
| 134 |
|
| 135 |
<xi:include href="libsystemd-pkgconfig.xml" /> |
| 136 |
|
| 137 |
<refsect1> |
| 138 |
<title>History</title> |
| 139 |
<para><function>sd_event_exit()</function> and |
| 140 |
<function>sd_event_get_exit_code()</function> were added in version 229.</para> |
| 141 |
</refsect1> |
| 142 |
|
| 143 |
<refsect1> |
| 144 |
<title>See Also</title> |
| 145 |
|
| 146 |
<para><simplelist type="inline"> |
| 147 |
<member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 148 |
<member><citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 149 |
<member><citerefentry><refentrytitle>sd_event_new</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 150 |
<member><citerefentry><refentrytitle>sd_event_add_exit</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 151 |
<member><citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 152 |
<member><citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 153 |
<member><citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 154 |
<member><citerefentry><refentrytitle>sd_event_add_defer</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 155 |
<member><citerefentry><refentrytitle>sd_event_add_inotify</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 156 |
</simplelist></para> |
| 157 |
</refsect1> |
| 158 |
|
| 159 |
</refentry> |