460bc3b373b4ffb1c7d4f00f381ca49cac1c6890
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/lttngerr.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
);
98 /* Print perror and goto end not failing. Show must go on. */
99 perror("epoll_ctl ADD");
102 perror("epoll_ctl ADD fatal");
109 if (events
->nb_fd
>= events
->events_size
) {
110 new_size
= 2 * events
->events_size
;
111 ptr
= realloc(events
->events
, new_size
* sizeof(struct epoll_event
));
113 perror("realloc epoll add");
116 events
->events
= ptr
;
117 events
->events_size
= new_size
;
128 * Remove a fd from the epoll set.
130 int compat_epoll_del(struct lttng_poll_event
*events
, int fd
)
134 if (events
== NULL
|| fd
< 0) {
138 ret
= epoll_ctl(events
->epfd
, EPOLL_CTL_DEL
, fd
, NULL
);
143 /* Print perror and goto end not failing. Show must go on. */
144 perror("epoll_ctl DEL");
147 perror("epoll_ctl DEL fatal");
150 perror("epoll_ctl del");
164 * Wait on epoll set. This is a blocking call of timeout value.
166 int compat_epoll_wait(struct lttng_poll_event
*events
, int timeout
)
170 if (events
== NULL
|| events
->events
== NULL
||
171 events
->events_size
< events
->nb_fd
) {
172 ERR("Wrong arguments in compat_epoll_wait");
177 ret
= epoll_wait(events
->epfd
, events
->events
, events
->nb_fd
, timeout
);
178 } while (ret
== -1 && errno
== EINTR
);
180 /* At this point, every error is fatal */
181 perror("epoll_wait");
192 * Setup poll set maximum size.
194 void compat_epoll_set_max_size(void)
199 poll_max_size
= DEFAULT_POLL_SIZE
;
201 fd
= open(COMPAT_EPOLL_PROC_PATH
, O_RDONLY
);
206 ret
= read(fd
, buf
, sizeof(buf
));
208 perror("read set max size");
212 poll_max_size
= atoi(buf
);
213 if (poll_max_size
<= 0) {
214 /* Extra precaution */
215 poll_max_size
= DEFAULT_POLL_SIZE
;
218 DBG("epoll set max size is %d", poll_max_size
);
This page took 0.035207 seconds and 3 git commands to generate.