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.
21 #include <sys/types.h>
26 #include <common/error.h>
27 #include <common/defaults.h>
31 unsigned int poll_max_size
;
34 * Create epoll set and allocate returned events structure.
36 int compat_epoll_create(struct lttng_poll_event
*events
, int size
, int flags
)
40 if (events
== NULL
|| size
<= 0) {
44 /* Don't bust the limit here */
45 if (size
> poll_max_size
) {
49 ret
= epoll_create1(flags
);
51 /* At this point, every error is fatal */
52 perror("epoll_create1");
58 /* This *must* be freed by using lttng_poll_free() */
59 events
->events
= zmalloc(size
* sizeof(struct epoll_event
));
60 if (events
->events
== NULL
) {
61 perror("zmalloc epoll set");
65 events
->events_size
= size
;
77 * Add a fd to the epoll set with requesting events.
79 int compat_epoll_add(struct lttng_poll_event
*events
, int fd
, uint32_t req_events
)
82 struct epoll_event ev
, *ptr
;
84 if (events
== NULL
|| events
->events
== NULL
|| fd
< 0) {
85 ERR("Bad compat epoll add arguments");
89 ev
.events
= req_events
;
92 ret
= epoll_ctl(events
->epfd
, EPOLL_CTL_ADD
, fd
, &ev
);
96 /* If exist, it's OK. */
100 /* Print perror and goto end not failing. Show must go on. */
101 perror("epoll_ctl ADD");
104 perror("epoll_ctl ADD fatal");
111 if (events
->nb_fd
>= events
->events_size
) {
112 new_size
= 2 * events
->events_size
;
113 ptr
= realloc(events
->events
, new_size
* sizeof(struct epoll_event
));
115 perror("realloc epoll add");
118 events
->events
= ptr
;
119 events
->events_size
= new_size
;
130 * Remove a fd from the epoll set.
132 int compat_epoll_del(struct lttng_poll_event
*events
, int fd
)
136 if (events
== NULL
|| fd
< 0) {
140 ret
= epoll_ctl(events
->epfd
, EPOLL_CTL_DEL
, fd
, NULL
);
145 /* Print perror and goto end not failing. Show must go on. */
146 perror("epoll_ctl DEL");
149 perror("epoll_ctl DEL fatal");
152 perror("epoll_ctl del");
166 * Wait on epoll set. This is a blocking call of timeout value.
168 int compat_epoll_wait(struct lttng_poll_event
*events
, int timeout
)
172 if (events
== NULL
|| events
->events
== NULL
||
173 events
->events_size
< events
->nb_fd
) {
174 ERR("Wrong arguments in compat_epoll_wait");
179 ret
= epoll_wait(events
->epfd
, events
->events
, events
->nb_fd
, timeout
);
180 } while (ret
== -1 && errno
== EINTR
);
182 /* At this point, every error is fatal */
183 perror("epoll_wait");
194 * Setup poll set maximum size.
196 void compat_epoll_set_max_size(void)
201 poll_max_size
= DEFAULT_POLL_SIZE
;
203 fd
= open(COMPAT_EPOLL_PROC_PATH
, O_RDONLY
);
208 ret
= read(fd
, buf
, sizeof(buf
));
210 perror("read set max size");
214 poll_max_size
= atoi(buf
);
215 if (poll_max_size
<= 0) {
216 /* Extra precaution */
217 poll_max_size
= DEFAULT_POLL_SIZE
;
220 DBG("epoll set max size is %d", poll_max_size
);
This page took 0.041366 seconds and 5 git commands to generate.