Debian Codegraph @

upstream/debian-unstable/man3/sd_event_add_defer.3

raw
1 '\" t
2 .TH "SD_EVENT_ADD_DEFER" "3" "" "systemd 261~rc3" "sd_event_add_defer"
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_add_defer, sd_event_add_post, sd_event_add_exit, sd_event_handler_t \- Add static event sources to an event loop
24 .SH "SYNOPSIS"
25 .sp
26 .ft B
27 .nf
28 #include <systemd/sd\-event\&.h>
29 .fi
30 .ft
31 .sp
32 .ft B
33 .nf
34 typedef struct sd_event_source sd_event_source;
35 .fi
36 .ft
37 .HP \w'typedef\ int\ (*sd_event_handler_t)('u
38 .BI "typedef int (*sd_event_handler_t)(sd_event_source\ *" "s" ", void\ *" "userdata" ");"
39 .HP \w'int\ sd_event_add_defer('u
40 .BI "int sd_event_add_defer(sd_event\ *" "event" ", sd_event_source\ **" "source" ", sd_event_handler_t\ " "handler" ", void\ *" "userdata" ");"
41 .HP \w'int\ sd_event_add_post('u
42 .BI "int sd_event_add_post(sd_event\ *" "event" ", sd_event_source\ **" "source" ", sd_event_handler_t\ " "handler" ", void\ *" "userdata" ");"
43 .HP \w'int\ sd_event_add_exit('u
44 .BI "int sd_event_add_exit(sd_event\ *" "event" ", sd_event_source\ **" "source" ", sd_event_handler_t\ " "handler" ", void\ *" "userdata" ");"
45 .SH "DESCRIPTION"
46 .PP
47 These three functions add new static event sources to an event loop\&. The event loop object is specified in the
48 \fIevent\fR
49 parameter, the event source object is returned in the
50 \fIsource\fR
51 parameter\&. The event sources are enabled statically and will "fire" when the event loop is run and the conditions described below are met\&.
52 .PP
53 The
54 \fIhandler\fR
55 is a function to call or
56 \fBNULL\fR\&. The handler function will be passed the
57 \fIuserdata\fR
58 pointer, which may be chosen freely by the caller\&. The handler may return negative to signal an error (see below), other return values are ignored\&. If
59 \fIhandler\fR
60 is
61 \fBNULL\fR, a default handler that calls
62 \fBsd_event_exit\fR(3)
63 will be used\&.
64 .PP
65 \fBsd_event_add_defer()\fR
66 adds a new event source that will be dispatched instantly, before the event loop goes to sleep again and waits for new events\&. By default, the handler will be called once (\fBSD_EVENT_ONESHOT\fR)\&. Note that if the event source is set to
67 \fBSD_EVENT_ON\fR
68 the event loop will never go to sleep again, but continuously call the handler, possibly interleaved with other event sources\&.
69 .PP
70 \fBsd_event_add_post()\fR
71 adds a new event source that is run before the event loop will sleep and wait for new events, but only after at least one other non\-post event source was dispatched\&. By default, the source is enabled permanently (\fBSD_EVENT_ON\fR)\&. Note that this event source type will still allow the event loop to go to sleep again, even if set to
72 \fBSD_EVENT_ON\fR, as long as no other event source is ever triggered\&.
73 .PP
74 \fBsd_event_add_exit()\fR
75 adds a new event source that will be dispatched when the event loop is terminated with
76 \fBsd_event_exit\fR(3)\&.
77 .PP
78 The
79 \fBsd_event_source_set_enabled\fR(3)
80 function may be used to enable the event source permanently (\fBSD_EVENT_ON\fR) or to make it fire just once (\fBSD_EVENT_ONESHOT\fR)\&.
81 .PP
82 If the handler function returns a negative error code, it will either be disabled after the invocation, even if the
83 \fBSD_EVENT_ON\fR
84 mode was requested before, or it will cause the loop to terminate, see
85 \fBsd_event_source_set_exit_on_failure\fR(3)\&.
86 .PP
87 To destroy an event source object use
88 \fBsd_event_source_unref\fR(3), but note that the event source is only removed from the event loop when all references to the event source are dropped\&. To make sure an event source does not fire anymore, even when there\*(Aqs still a reference to it kept, consider setting the event source to
89 \fBSD_EVENT_OFF\fR
90 with
91 \fBsd_event_source_set_enabled\fR(3)\&.
92 .PP
93 If the second parameter of these functions is passed as
94 \fBNULL\fR
95 no reference to the event source object is returned\&. In this case, the event source is considered "floating", and will be destroyed implicitly when the event loop itself is destroyed\&.
96 .PP
97 If the
98 \fIhandler\fR
99 parameter to
100 \fBsd_event_add_defer()\fR
101 or
102 \fBsd_event_add_post()\fR
103 is
104 \fBNULL\fR, and the event source fires, this will be considered a request to exit the event loop\&. In this case, the
105 \fIuserdata\fR
106 parameter, cast to an integer, is passed as the exit code parameter to
107 \fBsd_event_exit\fR(3)\&. Similar functionality is not available for
108 \fBsd_event_add_exit()\fR, as these types of event sources are only dispatched when exiting anyway\&.
109 .SH "RETURN VALUE"
110 .PP
111 On success, these functions return 0 or a positive integer\&. On failure, they return a negative errno\-style error code\&.
112 .SS "Errors"
113 .PP
114 Returned errors may indicate the following problems:
115 .PP
116 \fB\-ENOMEM\fR
117 .RS 4
118 Not enough memory to allocate an object\&.
119 .RE
120 .PP
121 \fB\-EINVAL\fR
122 .RS 4
123 An invalid argument has been passed\&.
124 .RE
125 .PP
126 \fB\-ESTALE\fR
127 .RS 4
128 The event loop is already terminated\&.
129 .RE
130 .PP
131 \fB\-ECHILD\fR
132 .RS 4
133 The event loop has been created in a different process, library or module instance\&.
134 .RE
135 .SH "NOTES"
136 .PP
137 Functions described here are available as a shared library, which can be compiled against and linked to with the
138 \fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
139 file\&.
140 .PP
141 The code described here uses
142 \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
143 \fBsetenv\fR(3)
144 from a parallel thread\&. It is recommended to only do calls to
145 \fBsetenv()\fR
146 from an early phase of the program when no other threads have been started\&.
147 .SH "HISTORY"
148 .PP
149 \fBsd_event_add_defer()\fR,
150 \fBsd_event_add_post()\fR,
151 \fBsd_event_add_exit()\fR, and
152 \fBsd_event_handler_t()\fR
153 were added in version 217\&.
154 .SH "SEE ALSO"
155 .PP
156 \fBsystemd\fR(1), \fBsd-event\fR(3), \fBsd_event_new\fR(3), \fBsd_event_now\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_source_set_enabled\fR(3), \fBsd_event_source_set_priority\fR(3), \fBsd_event_source_set_userdata\fR(3), \fBsd_event_source_set_description\fR(3), \fBsd_event_source_set_floating\fR(3), \fBsd_event_exit\fR(3)