| 1 |
'\" t |
| 2 |
.TH "SD_EVENT_SOURCE_SET_PREPARE" "3" "" "systemd 261~rc3" "sd_event_source_set_prepare" |
| 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_source_set_prepare \- Set a preparation callback for event sources |
| 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_source_set_prepare('u |
| 32 |
.BI "int sd_event_source_set_prepare(sd_event_source\ *" "source" ", sd_event_handler_t\ " "callback" ");" |
| 33 |
.HP \w'typedef\ int\ (*sd_event_handler_t)('u |
| 34 |
.BI "typedef int (*sd_event_handler_t)(sd_event_source\ *" "s" ", void\ *" "userdata" ");" |
| 35 |
.SH "DESCRIPTION" |
| 36 |
.PP |
| 37 |
\fBsd_event_source_set_prepare()\fR |
| 38 |
may be used to set a preparation callback for the event source object specified as |
| 39 |
\fIsource\fR\&. The callback function specified as |
| 40 |
\fIcallback\fR |
| 41 |
will be invoked immediately before the event loop goes to sleep to wait for incoming events\&. It is invoked with the user data pointer passed when the event source was created\&. The event source will be disabled if the callback function returns a negative error code\&. The callback function may be used to reconfigure the precise events to wait for\&. If the |
| 42 |
\fIcallback\fR |
| 43 |
parameter is passed as |
| 44 |
\fBNULL\fR |
| 45 |
the callback function is reset\&. |
| 46 |
.PP |
| 47 |
Event source objects have no preparation callback associated when they are first created with calls such as |
| 48 |
\fBsd_event_add_io\fR(3), |
| 49 |
\fBsd_event_add_time\fR(3)\&. Preparation callback functions are supported for all event source types with the exception of those created with |
| 50 |
\fBsd_event_add_exit\fR(3)\&. Preparation callback functions are dispatched in the order indicated by the event source\*(Aqs priority field, as set with |
| 51 |
\fBsd_event_source_set_priority\fR(3)\&. Preparation callbacks of disabled event sources (see |
| 52 |
\fBsd_event_source_set_enabled\fR(3)) are not invoked\&. |
| 53 |
.SH "RETURN VALUE" |
| 54 |
.PP |
| 55 |
On success, |
| 56 |
\fBsd_event_source_set_prepare()\fR |
| 57 |
returns a non\-negative integer\&. On failure, it returns a negative errno\-style error code\&. |
| 58 |
.SS "Errors" |
| 59 |
.PP |
| 60 |
Returned errors may indicate the following problems: |
| 61 |
.PP |
| 62 |
\fB\-EINVAL\fR |
| 63 |
.RS 4 |
| 64 |
\fIsource\fR |
| 65 |
is not a valid pointer to an |
| 66 |
sd_event_source |
| 67 |
object\&. |
| 68 |
.RE |
| 69 |
.PP |
| 70 |
\fB\-ESTALE\fR |
| 71 |
.RS 4 |
| 72 |
The event loop is already terminated\&. |
| 73 |
.RE |
| 74 |
.PP |
| 75 |
\fB\-ENOMEM\fR |
| 76 |
.RS 4 |
| 77 |
Not enough memory\&. |
| 78 |
.RE |
| 79 |
.PP |
| 80 |
\fB\-ECHILD\fR |
| 81 |
.RS 4 |
| 82 |
The event loop has been created in a different process, library or module instance\&. |
| 83 |
.RE |
| 84 |
.PP |
| 85 |
\fB\-EDOM\fR |
| 86 |
.RS 4 |
| 87 |
The specified event source has been created with |
| 88 |
\fBsd_event_add_exit\fR(3)\&. |
| 89 |
.RE |
| 90 |
.SH "NOTES" |
| 91 |
.PP |
| 92 |
Functions described here are available as a shared library, which can be compiled against and linked to with the |
| 93 |
\fBlibsystemd\fR\ \&\fBpkg-config\fR(1) |
| 94 |
file\&. |
| 95 |
.PP |
| 96 |
The code described here uses |
| 97 |
\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 |
| 98 |
\fBsetenv\fR(3) |
| 99 |
from a parallel thread\&. It is recommended to only do calls to |
| 100 |
\fBsetenv()\fR |
| 101 |
from an early phase of the program when no other threads have been started\&. |
| 102 |
.SH "HISTORY" |
| 103 |
.PP |
| 104 |
\fBsd_event_source_set_prepare()\fR |
| 105 |
and |
| 106 |
\fBsd_event_handler_t()\fR |
| 107 |
were added in version 229\&. |
| 108 |
.SH "SEE ALSO" |
| 109 |
.PP |
| 110 |
\fBsd-event\fR(3), \fBsd_event_add_io\fR(3), \fBsd_event_add_time\fR(3), \fBsd_event_add_signal\fR(3), \fBsd_event_add_child\fR(3), \fBsd_event_add_inotify\fR(3), \fBsd_event_add_defer\fR(3), \fBsd_event_source_set_enabled\fR(3), \fBsd_event_source_set_priority\fR(3), \fBsd_event_source_set_userdata\fR(3) |