2022-09-28 17:42:05 +08:00
|
|
|
<?xml version='1.0'?>
|
|
|
|
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
2023-12-25 22:48:33 +08:00
|
|
|
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
|
2022-09-28 17:42:05 +08:00
|
|
|
<!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
|
|
|
|
|
|
|
|
<refentry id="sd_event_set_signal_exit" xmlns:xi="http://www.w3.org/2001/XInclude">
|
|
|
|
|
|
|
|
<refentryinfo>
|
|
|
|
<title>sd_event_set_signal_exit</title>
|
|
|
|
<productname>systemd</productname>
|
|
|
|
</refentryinfo>
|
|
|
|
|
|
|
|
<refmeta>
|
|
|
|
<refentrytitle>sd_event_set_signal_exit</refentrytitle>
|
|
|
|
<manvolnum>3</manvolnum>
|
|
|
|
</refmeta>
|
|
|
|
|
|
|
|
<refnamediv>
|
|
|
|
<refname>sd_event_set_signal_exit</refname>
|
|
|
|
|
|
|
|
<refpurpose>Automatically leave event loop on <constant>SIGINT</constant> and <constant>SIGTERM</constant></refpurpose>
|
|
|
|
</refnamediv>
|
|
|
|
|
|
|
|
<refsynopsisdiv>
|
|
|
|
<funcsynopsis>
|
|
|
|
<funcsynopsisinfo>#include <systemd/sd-event.h></funcsynopsisinfo>
|
|
|
|
|
|
|
|
<funcprototype>
|
|
|
|
<funcdef>int <function>sd_event_set_signal_exit</function></funcdef>
|
|
|
|
<paramdef>sd_event *<parameter>event</parameter></paramdef>
|
|
|
|
<paramdef>int b</paramdef>
|
|
|
|
</funcprototype>
|
|
|
|
|
|
|
|
</funcsynopsis>
|
|
|
|
</refsynopsisdiv>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Description</title>
|
|
|
|
|
|
|
|
<para><function>sd_event_set_signal_exit()</function> may be used to ensure the event loop terminates
|
|
|
|
once a <constant>SIGINT</constant> or <constant>SIGTERM</constant> signal is received. It is a
|
2023-10-04 07:58:10 +08:00
|
|
|
convenience wrapper around invocations of
|
2022-09-28 17:42:05 +08:00
|
|
|
<citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
|
|
|
for both signals. The two signals are automatically added to the calling thread's signal mask (if a
|
|
|
|
program is multi-threaded care should be taken to either invoke this function before the first thread is
|
|
|
|
started or to manually block the two signals process-wide first).</para>
|
|
|
|
|
|
|
|
<para>If the parameter <parameter>b</parameter> is specified as true, the event loop will terminate on
|
|
|
|
<constant>SIGINT</constant> and <constant>SIGTERM</constant>. If specified as false, it will no
|
|
|
|
longer. When this functionality is turned off the calling thread's signal mask is restored to match the
|
|
|
|
state before it was turned on, for the two signals. By default the two signals are not handled by the
|
|
|
|
event loop, and Linux' default signal handling for them is in effect.</para>
|
|
|
|
|
|
|
|
<para>It's customary for UNIX programs to exit on either of these two signals, hence it's typically a
|
|
|
|
good idea to enable this functionality for the main event loop of a program.</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Return Value</title>
|
|
|
|
|
|
|
|
<para><function>sd_event_set_signal_exit()</function> returns a positive non-zero value when the setting
|
|
|
|
was successfully changed. It returns a zero when the specified setting was already in effect. On failure,
|
|
|
|
it returns a negative errno-style error code.</para>
|
|
|
|
|
|
|
|
<refsect2>
|
|
|
|
<title>Errors</title>
|
|
|
|
|
|
|
|
<para>Returned errors may indicate the following problems:</para>
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><constant>-ECHILD</constant></term>
|
|
|
|
|
2023-08-23 00:52:36 +08:00
|
|
|
<listitem><para>The event loop has been created in a different process, library or module instance.</para>
|
|
|
|
|
|
|
|
<xi:include href="version-info.xml" xpointer="v252"/></listitem>
|
2022-09-28 17:42:05 +08:00
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><constant>-EINVAL</constant></term>
|
|
|
|
|
2023-08-23 00:52:36 +08:00
|
|
|
<listitem><para>The passed event loop object was invalid.</para>
|
|
|
|
|
|
|
|
<xi:include href="version-info.xml" xpointer="v252"/></listitem>
|
2022-09-28 17:42:05 +08:00
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
</variablelist>
|
|
|
|
</refsect2>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<xi:include href="libsystemd-pkgconfig.xml" />
|
|
|
|
|
2023-09-04 20:46:35 +08:00
|
|
|
<refsect1>
|
|
|
|
<title>History</title>
|
|
|
|
<para><function>sd_event_set_signal_exit()</function> was added in version 252.</para>
|
|
|
|
</refsect1>
|
|
|
|
|
2022-09-28 17:42:05 +08:00
|
|
|
<refsect1>
|
|
|
|
<title>See Also</title>
|
|
|
|
|
2023-12-23 02:09:32 +08:00
|
|
|
<para><simplelist type="inline">
|
|
|
|
<member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
|
|
|
|
<member><citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
|
|
|
|
<member><citerefentry><refentrytitle>sd_event_new</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
|
|
|
|
<member><citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
|
|
|
|
</simplelist></para>
|
2022-09-28 17:42:05 +08:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
</refentry>
|