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>
30 unsigned int poll_max_size
;
33 * Create epoll set and allocate returned events structure.
35 int compat_epoll_create(struct lttng_poll_event
*events
, int size
, int flags
)
39 if (events
== NULL
|| size
<= 0) {
43 /* Don't bust the limit here */
44 if (size
> poll_max_size
) {
48 ret
= epoll_create1(flags
);
50 /* At this point, every error is fatal */
51 perror("epoll_create1");
57 /* This *must* be freed by using lttng_poll_free() */
58 events
->events
= zmalloc(size
* sizeof(struct epoll_event
));
59 if (events
->events
== NULL
) {
60 perror("zmalloc epoll set");
64 events
->events_size
= size
;
76 * Add a fd to the epoll set with requesting events.
78 int compat_epoll_add(struct lttng_poll_event
*events
, int fd
, uint32_t req_events
)
81 struct epoll_event ev
, *ptr
;
83 if (events
== NULL
|| events
->events
== NULL
|| fd
< 0) {
84 ERR("Bad compat epoll add arguments");
88 ev
.events
= req_events
;
91 ret
= epoll_ctl(events
->epfd
, EPOLL_CTL_ADD
, fd
, &ev
);
97 /* Print perror and goto end not failing. Show must go on. */
98 perror("epoll_ctl ADD");
101 perror("epoll_ctl ADD fatal");
108 if (events
->nb_fd
>= events
->events_size
) {
109 new_size
= 2 * events
->events_size
;
110 ptr
= realloc(events
->events
, new_size
* sizeof(struct epoll_event
));
112 perror("realloc epoll add");
115 events
->events
= ptr
;
116 events
->events_size
= new_size
;
127 * Remove a fd from the epoll set.
129 int compat_epoll_del(struct lttng_poll_event
*events
, int fd
)
133 if (events
== NULL
|| fd
< 0) {
137 ret
= epoll_ctl(events
->epfd
, EPOLL_CTL_DEL
, fd
, NULL
);
142 /* Print perror and goto end not failing. Show must go on. */
143 perror("epoll_ctl DEL");
146 perror("epoll_ctl DEL fatal");
149 perror("epoll_ctl del");
163 * Wait on epoll set. This is a blocking call of timeout value.
165 int compat_epoll_wait(struct lttng_poll_event
*events
, int timeout
)
169 if (events
== NULL
|| events
->events
== NULL
||
170 events
->events_size
< events
->nb_fd
) {
171 ERR("Wrong arguments in compat_epoll_wait");
176 ret
= epoll_wait(events
->epfd
, events
->events
, events
->nb_fd
, timeout
);
177 } while (ret
== -1 && errno
== EINTR
);
179 /* At this point, every error is fatal */
180 perror("epoll_wait");
191 * Setup poll set maximum size.
193 void compat_epoll_set_max_size(void)
198 poll_max_size
= LTTNG_POLL_DEFAULT_SIZE
;
200 fd
= open(LTTNG_EPOLL_PROC_PATH
, O_RDONLY
);
205 ret
= read(fd
, buf
, sizeof(buf
));
207 perror("read set max size");
211 poll_max_size
= atoi(buf
);
212 if (poll_max_size
<= 0) {
213 /* Extra precaution */
214 poll_max_size
= LTTNG_POLL_DEFAULT_SIZE
;
217 DBG("epoll set max size is %d", poll_max_size
);
This page took 0.034168 seconds and 4 git commands to generate.