]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/sd_event_set_signal_exit.xml
test: make coverage runs happy with capsule@.service
[thirdparty/systemd.git] / man / sd_event_set_signal_exit.xml
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_set_signal_exit" xmlns:xi="http://www.w3.org/2001/XInclude">
7
8 <refentryinfo>
9 <title>sd_event_set_signal_exit</title>
10 <productname>systemd</productname>
11 </refentryinfo>
12
13 <refmeta>
14 <refentrytitle>sd_event_set_signal_exit</refentrytitle>
15 <manvolnum>3</manvolnum>
16 </refmeta>
17
18 <refnamediv>
19 <refname>sd_event_set_signal_exit</refname>
20
21 <refpurpose>Automatically leave event loop on <constant>SIGINT</constant> and <constant>SIGTERM</constant></refpurpose>
22 </refnamediv>
23
24 <refsynopsisdiv>
25 <funcsynopsis>
26 <funcsynopsisinfo>#include &lt;systemd/sd-event.h&gt;</funcsynopsisinfo>
27
28 <funcprototype>
29 <funcdef>int <function>sd_event_set_signal_exit</function></funcdef>
30 <paramdef>sd_event *<parameter>event</parameter></paramdef>
31 <paramdef>int b</paramdef>
32 </funcprototype>
33
34 </funcsynopsis>
35 </refsynopsisdiv>
36
37 <refsect1>
38 <title>Description</title>
39
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>
47
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>
53
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>
56 </refsect1>
57
58 <refsect1>
59 <title>Return Value</title>
60
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>
64
65 <refsect2>
66 <title>Errors</title>
67
68 <para>Returned errors may indicate the following problems:</para>
69
70 <variablelist>
71
72 <varlistentry>
73 <term><constant>-ECHILD</constant></term>
74
75 <listitem><para>The event loop has been created in a different process, library or module instance.</para>
76
77 <xi:include href="version-info.xml" xpointer="v252"/></listitem>
78 </varlistentry>
79
80 <varlistentry>
81 <term><constant>-EINVAL</constant></term>
82
83 <listitem><para>The passed event loop object was invalid.</para>
84
85 <xi:include href="version-info.xml" xpointer="v252"/></listitem>
86 </varlistentry>
87
88 </variablelist>
89 </refsect2>
90 </refsect1>
91
92 <xi:include href="libsystemd-pkgconfig.xml" />
93
94 <refsect1>
95 <title>History</title>
96 <para><function>sd_event_set_signal_exit()</function> was added in version 252.</para>
97 </refsect1>
98
99 <refsect1>
100 <title>See Also</title>
101
102 <para><simplelist type="inline">
103 <member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
104 <member><citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
105 <member><citerefentry><refentrytitle>sd_event_new</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
106 <member><citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
107 </simplelist></para>
108 </refsect1>
109
110 </refentry>