X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fthread-utils.c;h=5e42d110fbc27d244acf9538f7c1da297b2c5b6b;hp=99b8298983fa6a7a8f489bcb7222a198b6d217dc;hb=b8a1b0bd3964381c9ec6a8df26bd37cd7405a83f;hpb=a7333da73c2083281c5ec833d041b7acf0d10d0b diff --git a/src/bin/lttng-sessiond/thread-utils.c b/src/bin/lttng-sessiond/thread-utils.c index 99b829898..5e42d110f 100644 --- a/src/bin/lttng-sessiond/thread-utils.c +++ b/src/bin/lttng-sessiond/thread-utils.c @@ -1,25 +1,16 @@ /* - * Copyright (C) 2011 - David Goulet - * Mathieu Desnoyers - * 2013 - Jérémie Galarneau + * Copyright (C) 2011 David Goulet + * Copyright (C) 2011 Mathieu Desnoyers + * Copyright (C) 2013 Jérémie Galarneau * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2 only, - * as published by the Free Software Foundation. + * SPDX-License-Identifier: GPL-2.0-only * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "lttng-sessiond.h" #include "utils.h" #include +#include /* * Quit pipe for all threads. This permits a single cancellation point @@ -67,43 +58,43 @@ int sessiond_check_thread_quit_pipe(int fd, uint32_t events) /* * Wait for a notification on the quit pipe (with a timeout). * + * A timeout value of -1U means no timeout. + * * Returns 1 if the caller should quit, 0 if the timeout was reached, and * -1 if an error was encountered. */ -int sessiond_wait_for_quit_pipe(unsigned int timeout_us) +int sessiond_wait_for_quit_pipe(int timeout_ms) { int ret; - fd_set read_fds; - struct timeval timeout; - - FD_ZERO(&read_fds); - FD_SET(thread_quit_pipe[0], &read_fds); - memset(&timeout, 0, sizeof(timeout)); - timeout.tv_usec = timeout_us; - - while (true) { - ret = select(thread_quit_pipe[0] + 1, &read_fds, NULL, NULL, - &timeout); - if (ret < 0 && errno == EINTR) { - /* Retry on interrupt. */ - continue; - } else { - break; - } - } + struct lttng_poll_event events; + ret = lttng_poll_create(&events, 1, LTTNG_CLOEXEC); + if (ret < 0) { + PERROR("Failed to initialize poll/epoll set"); + ret = -1; + goto end; + } + ret = lttng_poll_add(&events, thread_quit_pipe[0], LPOLLIN | LPOLLERR); + if (ret < 0) { + PERROR("Failed to add file descriptor to poll/epoll set"); + ret = -1; + goto end_clean_poll; + } + ret = lttng_poll_wait(&events, timeout_ms); if (ret > 0) { /* Should quit. */ ret = 1; } else if (ret < 0 && errno != EINTR) { /* Unknown error. */ - PERROR("Failed to select() thread quit pipe"); + PERROR("Failed to epoll()/poll() thread quit pipe"); ret = -1; } else { /* Timeout reached. */ ret = 0; } - +end_clean_poll: + lttng_poll_clean(&events); +end: return ret; }