X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fcommon%2Fcompat%2Fcompat-epoll.c;h=1380ce85527a74dae304b2777de5a72c489b6b5c;hb=6cd525e813795a1d5e38feac8dedf2c73ffb1274;hp=f014a0d783d434f57fc95a5c17e126f62946e74e;hpb=94cc2fd1d4c93bf52c9142999ad0355ad7bc7323;p=lttng-tools.git diff --git a/src/common/compat/compat-epoll.c b/src/common/compat/compat-epoll.c index f014a0d78..1380ce855 100644 --- a/src/common/compat/compat-epoll.c +++ b/src/common/compat/compat-epoll.c @@ -27,6 +27,8 @@ #include #include +#include +#include #include "poll.h" @@ -201,11 +203,15 @@ int compat_epoll_wait(struct lttng_poll_event *events, int timeout) */ if (events->nb_fd > events->alloc_size) { /* Expand if the nb_fd is higher than the actual size. */ - new_size = events->alloc_size << 1UL; + new_size = max_t(uint32_t, + 1U << utils_get_count_order_u32(events->nb_fd), + events->alloc_size << 1UL); } else if ((events->nb_fd << 1UL) <= events->alloc_size && events->nb_fd >= events->init_size) { /* Shrink if nb_fd multiplied by two is <= than the actual size. */ - new_size = events->alloc_size >> 1UL; + new_size = max_t(uint32_t, + utils_get_count_order_u32(events->nb_fd) >> 1U, + events->alloc_size >> 1U); } else { /* Indicate that we don't want to resize. */ new_size = 0; @@ -244,6 +250,7 @@ error: void compat_epoll_set_max_size(void) { int ret, fd; + size_t size_ret; char buf[64]; poll_max_size = DEFAULT_POLL_SIZE; @@ -253,11 +260,16 @@ void compat_epoll_set_max_size(void) return; } - ret = read(fd, buf, sizeof(buf)); - if (ret < 0) { + size_ret = lttng_read(fd, buf, sizeof(buf)); + /* + * Allow reading a file smaller than buf, but keep space for + * final \0. + */ + if (size_ret < 0 || size_ret >= sizeof(buf)) { PERROR("read set max size"); goto error; } + buf[size_ret] = '\0'; poll_max_size = atoi(buf); if (poll_max_size == 0) {