008dba7028dff9d0756914d50c4a1baf7effdbe7
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; only version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include <sys/types.h>
27 #include <common/error.h>
28 #include <common/defaults.h>
32 unsigned int poll_max_size
;
35 * Create epoll set and allocate returned events structure.
37 int compat_epoll_create(struct lttng_poll_event
*events
, int size
, int flags
)
41 if (events
== NULL
|| size
<= 0) {
45 /* Don't bust the limit here */
46 if (size
> poll_max_size
) {
50 ret
= epoll_create1(flags
);
52 /* At this point, every error is fatal */
53 PERROR("epoll_create1");
59 /* This *must* be freed by using lttng_poll_free() */
60 events
->events
= zmalloc(size
* sizeof(struct epoll_event
));
61 if (events
->events
== NULL
) {
62 PERROR("zmalloc epoll set");
66 events
->events_size
= size
;
72 ret
= close(events
->epfd
);
81 * Add a fd to the epoll set with requesting events.
83 int compat_epoll_add(struct lttng_poll_event
*events
, int fd
, uint32_t req_events
)
86 struct epoll_event ev
, *ptr
;
88 if (events
== NULL
|| events
->events
== NULL
|| fd
< 0) {
89 ERR("Bad compat epoll add arguments");
93 ev
.events
= req_events
;
96 ret
= epoll_ctl(events
->epfd
, EPOLL_CTL_ADD
, fd
, &ev
);
100 /* If exist, it's OK. */
104 /* Print PERROR and goto end not failing. Show must go on. */
105 PERROR("epoll_ctl ADD");
108 PERROR("epoll_ctl ADD fatal");
115 if (events
->nb_fd
>= events
->events_size
) {
116 new_size
= 2 * events
->events_size
;
117 ptr
= realloc(events
->events
, new_size
* sizeof(struct epoll_event
));
119 PERROR("realloc epoll add");
122 events
->events
= ptr
;
123 events
->events_size
= new_size
;
134 * Remove a fd from the epoll set.
136 int compat_epoll_del(struct lttng_poll_event
*events
, int fd
)
140 if (events
== NULL
|| fd
< 0) {
144 ret
= epoll_ctl(events
->epfd
, EPOLL_CTL_DEL
, fd
, NULL
);
149 /* Print PERROR and goto end not failing. Show must go on. */
150 PERROR("epoll_ctl DEL");
153 PERROR("epoll_ctl DEL fatal");
156 PERROR("epoll_ctl del");
170 * Wait on epoll set. This is a blocking call of timeout value.
172 int compat_epoll_wait(struct lttng_poll_event
*events
, int timeout
)
176 if (events
== NULL
|| events
->events
== NULL
||
177 events
->events_size
< events
->nb_fd
) {
178 ERR("Wrong arguments in compat_epoll_wait");
183 ret
= epoll_wait(events
->epfd
, events
->events
, events
->nb_fd
, timeout
);
184 } while (ret
== -1 && errno
== EINTR
);
186 /* At this point, every error is fatal */
187 PERROR("epoll_wait");
198 * Setup poll set maximum size.
200 void compat_epoll_set_max_size(void)
205 poll_max_size
= DEFAULT_POLL_SIZE
;
207 fd
= open(COMPAT_EPOLL_PROC_PATH
, O_RDONLY
);
212 ret
= read(fd
, buf
, sizeof(buf
));
214 PERROR("read set max size");
218 poll_max_size
= atoi(buf
);
219 if (poll_max_size
<= 0) {
220 /* Extra precaution */
221 poll_max_size
= DEFAULT_POLL_SIZE
;
224 DBG("epoll set max size is %d", poll_max_size
);
This page took 0.064221 seconds and 4 git commands to generate.