2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
6 <refentry id="sd_event_set_signal_exit" xmlns:xi="http://www.w3.org/2001/XInclude">
9 <title>sd_event_set_signal_exit</title>
10 <productname>systemd</productname>
14 <refentrytitle>sd_event_set_signal_exit</refentrytitle>
15 <manvolnum>3</manvolnum>
19 <refname>sd_event_set_signal_exit</refname>
21 <refpurpose>Automatically leave event loop on <constant>SIGINT</constant> and <constant>SIGTERM</constant></refpurpose>
26 <funcsynopsisinfo>#include <systemd/sd-event.h></funcsynopsisinfo>
29 <funcdef>int <function>sd_event_set_signal_exit</function></funcdef>
30 <paramdef>sd_event *<parameter>event</parameter></paramdef>
31 <paramdef>int b</paramdef>
38 <title>Description</title>
40 <para><function>sd_event_set_signal_exit()</function> may be used to ensure the event loop terminates
41 once a <constant>SIGINT</constant> or <constant>SIGTERM</constant> signal is received. It is a
42 convenience wrapper around invocations of
43 <citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>
44 for both signals. The two signals are automatically added to the calling thread's signal mask (if a
45 program is multi-threaded care should be taken to either invoke this function before the first thread is
46 started or to manually block the two signals process-wide first).</para>
48 <para>If the parameter <parameter>b</parameter> is specified as true, the event loop will terminate on
49 <constant>SIGINT</constant> and <constant>SIGTERM</constant>. If specified as false, it will no
50 longer. When this functionality is turned off the calling thread's signal mask is restored to match the
51 state before it was turned on, for the two signals. By default the two signals are not handled by the
52 event loop, and Linux' default signal handling for them is in effect.</para>
54 <para>It's customary for UNIX programs to exit on either of these two signals, hence it's typically a
55 good idea to enable this functionality for the main event loop of a program.</para>
59 <title>Return Value</title>
61 <para><function>sd_event_set_signal_exit()</function> returns a positive non-zero value when the setting
62 was successfully changed. It returns a zero when the specified setting was already in effect. On failure,
63 it returns a negative errno-style error code.</para>
68 <para>Returned errors may indicate the following problems:</para>
73 <term><constant>-ECHILD</constant></term>
75 <listitem><para>The event loop has been created in a different process, library or module instance.</para>
77 <xi:include href="version-info.xml" xpointer="v252"/></listitem>
81 <term><constant>-EINVAL</constant></term>
83 <listitem><para>The passed event loop object was invalid.</para>
85 <xi:include href="version-info.xml" xpointer="v252"/></listitem>
92 <xi:include href="libsystemd-pkgconfig.xml" />
95 <title>History</title>
96 <para><function>sd_event_set_signal_exit()</function> was added in version 252.</para>
100 <title>See Also</title>
103 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
104 <citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
105 <citerefentry><refentrytitle>sd_event_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
106 <citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>