| 1 |
'\" t |
| 2 |
.TH "SD_EVENT_SET_SIGNAL_EXIT" "3" "" "systemd 261~rc3" "sd_event_set_signal_exit" |
| 3 |
.\" ----------------------------------------------------------------- |
| 4 |
.\" * Define some portability stuff |
| 5 |
.\" ----------------------------------------------------------------- |
| 6 |
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 7 |
.\" http://bugs.debian.org/507673 |
| 8 |
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html |
| 9 |
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 10 |
.ie \n(.g .ds Aq \(aq |
| 11 |
.el .ds Aq ' |
| 12 |
.\" ----------------------------------------------------------------- |
| 13 |
.\" * set default formatting |
| 14 |
.\" ----------------------------------------------------------------- |
| 15 |
.\" disable hyphenation |
| 16 |
.nh |
| 17 |
.\" disable justification (adjust text to left margin only) |
| 18 |
.ad l |
| 19 |
.\" ----------------------------------------------------------------- |
| 20 |
.\" * MAIN CONTENT STARTS HERE * |
| 21 |
.\" ----------------------------------------------------------------- |
| 22 |
.SH "NAME" |
| 23 |
sd_event_set_signal_exit \- Automatically leave event loop on \fBSIGINT\fR and \fBSIGTERM\fR |
| 24 |
.SH "SYNOPSIS" |
| 25 |
.sp |
| 26 |
.ft B |
| 27 |
.nf |
| 28 |
#include <systemd/sd\-event\&.h> |
| 29 |
.fi |
| 30 |
.ft |
| 31 |
.HP \w'int\ sd_event_set_signal_exit('u |
| 32 |
.BI "int sd_event_set_signal_exit(sd_event\ *" "event" ", int\ b);" |
| 33 |
.SH "DESCRIPTION" |
| 34 |
.PP |
| 35 |
\fBsd_event_set_signal_exit()\fR |
| 36 |
may be used to ensure the event loop terminates once a |
| 37 |
\fBSIGINT\fR |
| 38 |
or |
| 39 |
\fBSIGTERM\fR |
| 40 |
signal is received\&. It is a convenience wrapper around invocations of |
| 41 |
\fBsd_event_add_signal\fR(3) |
| 42 |
for both signals\&. The two signals are automatically added to the calling thread\*(Aqs 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)\&. |
| 43 |
.PP |
| 44 |
If the parameter |
| 45 |
\fIb\fR |
| 46 |
is specified as true, the event loop will terminate on |
| 47 |
\fBSIGINT\fR |
| 48 |
and |
| 49 |
\fBSIGTERM\fR\&. If specified as false, it will no longer\&. When this functionality is turned off the calling thread\*(Aqs 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\*(Aq default signal handling for them is in effect\&. |
| 50 |
.PP |
| 51 |
It is customary for UNIX programs to exit on either of these two signals, hence it is typically a good idea to enable this functionality for the main event loop of a program\&. |
| 52 |
.SH "RETURN VALUE" |
| 53 |
.PP |
| 54 |
\fBsd_event_set_signal_exit()\fR |
| 55 |
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\&. |
| 56 |
.SS "Errors" |
| 57 |
.PP |
| 58 |
Returned errors may indicate the following problems: |
| 59 |
.PP |
| 60 |
\fB\-ECHILD\fR |
| 61 |
.RS 4 |
| 62 |
The event loop has been created in a different process, library or module instance\&. |
| 63 |
.sp |
| 64 |
Added in version 252\&. |
| 65 |
.RE |
| 66 |
.PP |
| 67 |
\fB\-EINVAL\fR |
| 68 |
.RS 4 |
| 69 |
The passed event loop object was invalid\&. |
| 70 |
.sp |
| 71 |
Added in version 252\&. |
| 72 |
.RE |
| 73 |
.SH "NOTES" |
| 74 |
.PP |
| 75 |
Functions described here are available as a shared library, which can be compiled against and linked to with the |
| 76 |
\fBlibsystemd\fR\ \&\fBpkg-config\fR(1) |
| 77 |
file\&. |
| 78 |
.PP |
| 79 |
The code described here uses |
| 80 |
\fBgetenv\fR(3), which is declared to be not multi\-thread\-safe\&. This means that the code calling the functions described here must not call |
| 81 |
\fBsetenv\fR(3) |
| 82 |
from a parallel thread\&. It is recommended to only do calls to |
| 83 |
\fBsetenv()\fR |
| 84 |
from an early phase of the program when no other threads have been started\&. |
| 85 |
.SH "HISTORY" |
| 86 |
.PP |
| 87 |
\fBsd_event_set_signal_exit()\fR |
| 88 |
was added in version 252\&. |
| 89 |
.SH "SEE ALSO" |
| 90 |
.PP |
| 91 |
\fBsystemd\fR(1), \fBsd-event\fR(3), \fBsd_event_new\fR(3), \fBsd_event_add_signal\fR(3) |