]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/epoll_ctl.2
epoll_ctl.2: Order ERRORS alphabetically
[thirdparty/man-pages.git] / man2 / epoll_ctl.2
1 .\" Copyright (C) 2003 Davide Libenzi
2 .\" Davide Libenzi <davidel@xmailserver.org>
3 .\"
4 .\" %%%LICENSE_START(GPLv2+_SW_3_PARA)
5 .\" This program is free software; you can redistribute it and/or modify
6 .\" it under the terms of the GNU General Public License as published by
7 .\" the Free Software Foundation; either version 2 of the License, or
8 .\" (at your option) any later version.
9 .\"
10 .\" This program is distributed in the hope that it will be useful,
11 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
12 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 .\" GNU General Public License for more details.
14 .\"
15 .\" You should have received a copy of the GNU General Public
16 .\" License along with this manual; if not, see
17 .\" <http://www.gnu.org/licenses/>.
18 .\" %%%LICENSE_END
19 .\"
20 .TH EPOLL_CTL 2 2016-03-15 "Linux" "Linux Programmer's Manual"
21 .SH NAME
22 epoll_ctl \- control interface for an epoll file descriptor
23 .SH SYNOPSIS
24 .B #include <sys/epoll.h>
25 .sp
26 .BI "int epoll_ctl(int " epfd ", int " op ", int " fd \
27 ", struct epoll_event *" event );
28 .SH DESCRIPTION
29 This system call performs control operations on the
30 .BR epoll (7)
31 instance
32 referred to by the file descriptor
33 .IR epfd .
34 It requests that the operation
35 .I op
36 be performed for the target file descriptor,
37 .IR fd .
38
39 Valid values for the
40 .I op
41 argument are:
42 .TP
43 .B EPOLL_CTL_ADD
44 Register the target file descriptor
45 .I fd
46 on the
47 .B epoll
48 instance referred to by the file descriptor
49 .I epfd
50 and associate the event
51 .I event
52 with the internal file linked to
53 .IR fd .
54 .TP
55 .B EPOLL_CTL_MOD
56 Change the event
57 .I event
58 associated with the target file descriptor
59 .IR fd .
60 .TP
61 .B EPOLL_CTL_DEL
62 Remove (deregister) the target file descriptor
63 .I fd
64 from the
65 .B epoll
66 instance referred to by
67 .IR epfd .
68 The
69 .I event
70 is ignored and can be NULL (but see BUGS below).
71 .PP
72 The
73 .I event
74 argument describes the object linked to the file descriptor
75 .IR fd .
76 The
77 .I struct epoll_event
78 is defined as:
79 .sp
80 .in +4n
81 .nf
82 typedef union epoll_data {
83 void *ptr;
84 int fd;
85 uint32_t u32;
86 uint64_t u64;
87 } epoll_data_t;
88
89 struct epoll_event {
90 uint32_t events; /* Epoll events */
91 epoll_data_t data; /* User data variable */
92 };
93 .fi
94 .in
95
96 The
97 .I events
98 member is a bit mask composed using the following available event
99 types:
100 .TP
101 .B EPOLLIN
102 The associated file is available for
103 .BR read (2)
104 operations.
105 .TP
106 .B EPOLLOUT
107 The associated file is available for
108 .BR write (2)
109 operations.
110 .TP
111 .BR EPOLLRDHUP " (since Linux 2.6.17)"
112 Stream socket peer closed connection,
113 or shut down writing half of connection.
114 (This flag is especially useful for writing simple code to detect
115 peer shutdown when using Edge Triggered monitoring.)
116 .TP
117 .B EPOLLPRI
118 There is urgent data available for
119 .BR read (2)
120 operations.
121 .TP
122 .B EPOLLERR
123 Error condition happened on the associated file descriptor.
124 .BR epoll_wait (2)
125 will always wait for this event; it is not necessary to set it in
126 .IR events .
127 .TP
128 .B EPOLLHUP
129 Hang up happened on the associated file descriptor.
130 .BR epoll_wait (2)
131 will always wait for this event; it is not necessary to set it in
132 .IR events .
133 Note that when reading from a channel such as a pipe or a stream socket,
134 this event merely indicates that the peer closed its end of the channel.
135 Subsequent reads from the channel will return 0 (end of file)
136 only after all outstanding data in the channel has been consumed.
137 .TP
138 .B EPOLLET
139 Sets the Edge Triggered behavior for the associated file descriptor.
140 The default behavior for
141 .B epoll
142 is Level Triggered.
143 See
144 .BR epoll (7)
145 for more detailed information about Edge and Level Triggered event
146 distribution architectures.
147 .TP
148 .BR EPOLLONESHOT " (since Linux 2.6.2)"
149 Sets the one-shot behavior for the associated file descriptor.
150 This means that after an event is pulled out with
151 .BR epoll_wait (2)
152 the associated file descriptor is internally disabled and no other events
153 will be reported by the
154 .B epoll
155 interface.
156 The user must call
157 .BR epoll_ctl ()
158 with
159 .B EPOLL_CTL_MOD
160 to rearm the file descriptor with a new event mask.
161 .TP
162 .BR EPOLLWAKEUP " (since Linux 3.5)"
163 .\" commit 4d7e30d98939a0340022ccd49325a3d70f7e0238
164 If
165 .B EPOLLONESHOT
166 and
167 .B EPOLLET
168 are clear and the process has the
169 .B CAP_BLOCK_SUSPEND
170 capability,
171 ensure that the system does not enter "suspend" or
172 "hibernate" while this event is pending or being processed.
173 The event is considered as being "processed" from the time
174 when it is returned by a call to
175 .BR epoll_wait (2)
176 until the next call to
177 .BR epoll_wait (2)
178 on the same
179 .BR epoll (7)
180 file descriptor,
181 the closure of that file descriptor,
182 the removal of the event file descriptor with
183 .BR EPOLL_CTL_DEL ,
184 or the clearing of
185 .B EPOLLWAKEUP
186 for the event file descriptor with
187 .BR EPOLL_CTL_MOD .
188 See also BUGS.
189 .TP
190 .BR EPOLLEXCLUSIVE " (since Linux 4.5)"
191 Sets an exclusive wakeup mode for the epoll file descriptor that is being
192 attached to the target file descriptor,
193 .IR fd .
194 When a wakeup event occurs and multiple epoll file descriptors
195 are attached to the same target file using
196 .BR EPOLLEXCLUSIVE ,
197 one or more of the epoll file descriptors will receive an event with
198 .BR epoll_wait (2).
199 The default in this scenario (when
200 .BR EPOLLEXCLUSIVE
201 is not set) is for all epoll file descriptors to receive an event.
202 .BR EPOLLEXCLUSIVE
203 is thus useful for avoiding thundering herd problems in certain scenarios.
204
205 If the same file descriptor is in multiple epoll instances,
206 some with the
207 .BR EPOLLEXCLUSIVE
208 flag, and others without, then events will provided to all epoll
209 instances that did not specify
210 .BR EPOLLEXCLUSIVE ,
211 and at least one of the epoll instances that did specify
212 .BR EPOLLEXCLUSIVE .
213
214 The following values may be specified in conjunction with
215 .BR EPOLLEXCLUSIVE :
216 .BR EPOLLIN ,
217 .BR EPOLLOUT ,
218 .BR EPOLLWAKEUP,
219 and
220 .BR EPOLLET .
221 .BR EPOLLHUP
222 and
223 .BR EPOLLERR
224 can also be specified, but this is not required:
225 as usual, these events are always reported if they occur,
226 regardless of whether they are specified in
227 .IR events .
228 Attempts to specify other values in
229 .I events
230 yield an error.
231 .B EPOLLEXCLUSIVE
232 may be used only in an
233 .B EPOLL_CTL_ADD
234 operation; attempts to employ it with
235 .B EPOLL_CTL_MOD
236 yield an error.
237 If
238 .B EPOLLEXCLUSIVE
239 has set using
240 .BR epoll_ctl (),
241 then a subsequent
242 .B EPOLL_CTL_MOD
243 on the same
244 .IR epfd ",\ " fd
245 pair yields an error.
246 A call to
247 .BR epoll_ctl ()
248 that specifies
249 .B EPOLLEXCLUSIVE
250 in
251 .I events
252 and specifies the target file descriptor
253 .I fd
254 as an epoll instance will likewise fail.
255 The error in all of these cases is
256 .BR EINVAL .
257 .SH RETURN VALUE
258 When successful,
259 .BR epoll_ctl ()
260 returns zero.
261 When an error occurs,
262 .BR epoll_ctl ()
263 returns \-1 and
264 .I errno
265 is set appropriately.
266 .SH ERRORS
267 .TP
268 .B EBADF
269 .I epfd
270 or
271 .I fd
272 is not a valid file descriptor.
273 .TP
274 .B EEXIST
275 .I op
276 was
277 .BR EPOLL_CTL_ADD ,
278 and the supplied file descriptor
279 .I fd
280 is already registered with this epoll instance.
281 .TP
282 .B EINVAL
283 .I epfd
284 is not an
285 .B epoll
286 file descriptor,
287 or
288 .I fd
289 is the same as
290 .IR epfd ,
291 or the requested operation
292 .I op
293 is not supported by this interface.
294 .TP
295 .B EINVAL
296 An invalid event type was specified along with
297 .B EPOLLEXCLUSIVE
298 in
299 .IR events .
300 .TP
301 .B EINVAL
302 .I op
303 was
304 .B EPOLL_CTL_MOD
305 and
306 .IR events
307 included
308 .BR EPOLLEXCLUSIVE .
309 .TP
310 .B EINVAL
311 .I op
312 was
313 .B EPOLL_CTL_MOD
314 and the
315 .BR EPOLLEXCLUSIVE
316 flag has previously been applied to this
317 .IR epfd ",\ " fd
318 pair.
319 .TP
320 .B EINVAL
321 .BR EPOLLEXCLUSIVE
322 was specified in
323 .IR event
324 and
325 .I fd
326 refers to an epoll instance.
327 .TP
328 .B ELOOP
329 .I fd
330 refers to an epoll instance and this
331 .B EPOLL_CTL_ADD
332 operation would result in a circular loop of epoll instances
333 monitoring one another.
334 .TP
335 .B ENOENT
336 .I op
337 was
338 .B EPOLL_CTL_MOD
339 or
340 .BR EPOLL_CTL_DEL ,
341 and
342 .I fd
343 is not registered with this epoll instance.
344 .TP
345 .B ENOMEM
346 There was insufficient memory to handle the requested
347 .I op
348 control operation.
349 .TP
350 .B ENOSPC
351 The limit imposed by
352 .I /proc/sys/fs/epoll/max_user_watches
353 was encountered while trying to register
354 .RB ( EPOLL_CTL_ADD )
355 a new file descriptor on an epoll instance.
356 See
357 .BR epoll (7)
358 for further details.
359 .TP
360 .B EPERM
361 The target file
362 .I fd
363 does not support
364 .BR epoll .
365 This error can occur if
366 .I fd
367 refers to, for example, a regular file or a directory.
368 .SH VERSIONS
369 .BR epoll_ctl ()
370 was added to the kernel in version 2.6.
371 .\" To be precise: kernel 2.5.44.
372 .\" The interface should be finalized by Linux kernel 2.5.66.
373 .SH CONFORMING TO
374 .BR epoll_ctl ()
375 is Linux-specific.
376 Library support is provided in glibc starting with version 2.3.2.
377 .SH NOTES
378 The
379 .B epoll
380 interface supports all file descriptors that support
381 .BR poll (2).
382 .SH BUGS
383 In kernel versions before 2.6.9, the
384 .B EPOLL_CTL_DEL
385 operation required a non-null pointer in
386 .IR event ,
387 even though this argument is ignored.
388 Since Linux 2.6.9,
389 .I event
390 can be specified as NULL
391 when using
392 .BR EPOLL_CTL_DEL .
393 Applications that need to be portable to kernels before 2.6.9
394 should specify a non-null pointer in
395 .IR event .
396
397 If
398 .B EPOLLWAKEUP
399 is specified in
400 .IR flags ,
401 but the caller does not have the
402 .BR CAP_BLOCK_SUSPEND
403 capability, then the
404 .B EPOLLWAKEUP
405 flag is
406 .IR "silently ignored" .
407 This unfortunate behavior is necessary because no validity
408 checks were performed on the
409 .IR flags
410 argument in the original implementation, and the addition of the
411 .B EPOLLWAKEUP
412 with a check that caused the call to fail if the caller did not have the
413 .B CAP_BLOCK_SUSPEND
414 capability caused a breakage in at least one existing user-space
415 application that happened to randomly (and uselessly) specify this bit.
416 .\" commit a8159414d7e3af7233e7a5a82d1c5d85379bd75c (behavior change)
417 .\" https://lwn.net/Articles/520198/
418 A robust application should therefore double check that it has the
419 .B CAP_BLOCK_SUSPEND
420 capability if attempting to use the
421 .B EPOLLWAKEUP
422 flag.
423 .SH SEE ALSO
424 .BR epoll_create (2),
425 .BR epoll_wait (2),
426 .BR poll (2),
427 .BR epoll (7)