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>
29 unsigned int poll_max_size
;
32 * Create epoll set and allocate returned events structure.
34 int compat_epoll_create(struct lttng_poll_event
*events
, int size
, int flags
)
38 if (events
== NULL
|| size
<= 0) {
42 /* Don't bust the limit here */
43 if (size
> poll_max_size
) {
47 ret
= epoll_create1(flags
);
49 /* At this point, every error is fatal */
50 perror("epoll_create1");
56 /* This *must* be freed by using lttng_poll_free() */
57 events
->events
= zmalloc(size
* sizeof(struct epoll_event
));
58 if (events
->events
== NULL
) {
59 perror("malloc epoll set");
63 events
->events_size
= size
;
75 * Add a fd to the epoll set with requesting events.
77 int compat_epoll_add(struct lttng_poll_event
*events
, int fd
, uint32_t req_events
)
80 struct epoll_event ev
, *ptr
;
82 if (events
== NULL
|| events
->events
== NULL
|| fd
< 0) {
83 ERR("Bad compat epoll add arguments");
87 ev
.events
= req_events
;
90 ret
= epoll_ctl(events
->epfd
, EPOLL_CTL_ADD
, fd
, &ev
);
96 /* Print perror and goto end not failing. Show must go on. */
97 perror("epoll_ctl ADD");
100 perror("epoll_ctl ADD fatal");
107 if (events
->nb_fd
>= events
->events_size
) {
108 new_size
= 2 * events
->events_size
;
109 ptr
= realloc(events
->events
, new_size
* sizeof(struct epoll_event
));
111 perror("realloc epoll add");
114 events
->events
= ptr
;
115 events
->events_size
= new_size
;
126 * Remove a fd from the epoll set.
128 int compat_epoll_del(struct lttng_poll_event
*events
, int fd
)
132 if (events
== NULL
|| fd
< 0) {
136 ret
= epoll_ctl(events
->epfd
, EPOLL_CTL_DEL
, fd
, NULL
);
141 /* Print perror and goto end not failing. Show must go on. */
142 perror("epoll_ctl DEL");
145 perror("epoll_ctl DEL fatal");
148 perror("epoll_ctl del");
162 * Wait on epoll set. This is a blocking call of timeout value.
164 int compat_epoll_wait(struct lttng_poll_event
*events
, int timeout
)
168 if (events
== NULL
|| events
->events
== NULL
||
169 events
->events_size
< events
->nb_fd
) {
170 ERR("Wrong arguments in compat_epoll_wait");
175 ret
= epoll_wait(events
->epfd
, events
->events
, events
->nb_fd
, timeout
);
176 } while (ret
== -1 && errno
== EINTR
);
178 /* At this point, every error is fatal */
179 perror("epoll_wait");
190 * Setup poll set maximum size.
192 void compat_epoll_set_max_size(void)
197 poll_max_size
= LTTNG_POLL_DEFAULT_SIZE
;
199 fd
= open(LTTNG_EPOLL_PROC_PATH
, O_RDONLY
);
204 ret
= read(fd
, buf
, sizeof(buf
));
206 perror("read set max size");
210 poll_max_size
= atoi(buf
);
211 if (poll_max_size
<= 0) {
212 /* Extra precaution */
213 poll_max_size
= LTTNG_POLL_DEFAULT_SIZE
;
216 DBG("epoll set max size is %d", poll_max_size
);
This page took 0.039016 seconds and 4 git commands to generate.