*
*/
-#include "lttng-sessiond.h"
-#include "health-sessiond.h"
-#include <common/macros.h>
-#include <common/error.h>
-#include <common/utils.h>
-#include <common/pipe.h>
+#include "health-sessiond.hpp"
+#include "lttng-sessiond.hpp"
+#include "thread.hpp"
+#include "utils.hpp"
+
+#include <common/error.hpp>
+#include <common/macros.hpp>
+#include <common/pipe.hpp>
+#include <common/utils.hpp>
+
+#include <fcntl.h>
#include <inttypes.h>
#include <sys/stat.h>
-#include "utils.h"
-#include "thread.h"
+namespace {
struct thread_notifiers {
struct lttng_pipe *quit_pipe;
sem_t ready;
};
+} /* namespace */
-static
-void mark_thread_as_ready(struct thread_notifiers *notifiers)
+static void mark_thread_as_ready(struct thread_notifiers *notifiers)
{
DBG("Marking health management thread as ready");
sem_post(¬ifiers->ready);
}
-static
-void wait_until_thread_is_ready(struct thread_notifiers *notifiers)
+static void wait_until_thread_is_ready(struct thread_notifiers *notifiers)
{
DBG("Waiting for health management thread to be ready");
sem_wait(¬ifiers->ready);
static void *thread_manage_health(void *data)
{
const bool is_root = (getuid() == 0);
- int sock = -1, new_sock = -1, ret, i, pollfd, err = -1;
- uint32_t revents, nb_fd;
+ int sock = -1, new_sock = -1, ret, i, err = -1;
+ uint32_t nb_fd;
struct lttng_poll_event events;
struct health_comm_msg msg;
struct health_comm_reply reply;
/* Thread-specific quit pipe. */
struct thread_notifiers *notifiers = (thread_notifiers *) data;
- const int quit_pipe_read_fd = lttng_pipe_get_readfd(
- notifiers->quit_pipe);
+ const auto thread_quit_pipe_fd = lttng_pipe_get_readfd(notifiers->quit_pipe);
DBG("[thread] Manage health check started");
/*
* Created with a size of two for:
- * - client socket
+ * - health client socket
* - thread quit pipe
*/
ret = lttng_poll_create(&events, 2, LTTNG_CLOEXEC);
}
ret = chmod(the_config.health_unix_sock_path.value,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
if (ret < 0) {
- ERR("Unable to set permissions on %s", the_config.health_unix_sock_path.value);
+ ERR("Unable to set permissions on %s",
+ the_config.health_unix_sock_path.value);
PERROR("chmod");
goto error;
}
goto error;
}
- ret = lttng_poll_add(&events, quit_pipe_read_fd, LPOLLIN | LPOLLERR);
+ ret = lttng_poll_add(&events, thread_quit_pipe_fd, LPOLLIN);
if (ret < 0) {
goto error;
}
- /* Add the application registration socket */
+ /* Add the health client socket. */
ret = lttng_poll_add(&events, sock, LPOLLIN | LPOLLPRI);
if (ret < 0) {
goto error;
}
mark_thread_as_ready(notifiers);
- while (1) {
+ while (true) {
DBG("Health check ready");
/* Infinite blocking call, waiting for transmission */
-restart:
+ restart:
ret = lttng_poll_wait(&events, -1);
if (ret < 0) {
/*
for (i = 0; i < nb_fd; i++) {
/* Fetch once the poll data */
- revents = LTTNG_POLL_GETEV(&events, i);
- pollfd = LTTNG_POLL_GETFD(&events, i);
-
- /* Event on the registration socket */
- if (pollfd == sock) {
- if (revents & LPOLLIN) {
- continue;
- } else if (revents & (LPOLLERR | LPOLLHUP | LPOLLRDHUP)) {
- ERR("Health socket poll error");
- goto error;
- } else {
- ERR("Unexpected poll events %u for sock %d", revents, pollfd);
- goto error;
- }
- } else {
- /* Event on the thread's quit pipe. */
+ const auto revents = LTTNG_POLL_GETEV(&events, i);
+ const auto pollfd = LTTNG_POLL_GETFD(&events, i);
+
+ /* Activity on thread quit pipe, exiting. */
+ if (pollfd == thread_quit_pipe_fd) {
+ DBG("Activity on thread quit pipe");
err = 0;
goto exit;
}
+
+ /* Event on the health client socket. */
+ if (revents & LPOLLIN) {
+ continue;
+ } else if (revents & (LPOLLERR | LPOLLHUP | LPOLLRDHUP)) {
+ ERR("Health socket poll error");
+ goto error;
+ } else {
+ ERR("Unexpected poll events %u for sock %d", revents, pollfd);
+ goto error;
+ }
}
new_sock = lttcomm_accept_unix_sock(sock);
(void) utils_set_fd_cloexec(new_sock);
DBG("Receiving data from client for health...");
- ret = lttcomm_recv_unix_sock(new_sock, (void *)&msg, sizeof(msg));
+ ret = lttcomm_recv_unix_sock(new_sock, (void *) &msg, sizeof(msg));
if (ret <= 0) {
DBG("Nothing recv() from client... continuing");
ret = close(new_sock);
DBG2("Health check return value %" PRIx64, reply.ret_code);
- ret = lttcomm_send_unix_sock(new_sock, (void *) &reply,
- sizeof(reply));
+ ret = lttcomm_send_unix_sock(new_sock, (void *) &reply, sizeof(reply));
if (ret < 0) {
ERR("Failed to send health data back to client");
}
lttng_poll_clean(&events);
rcu_unregister_thread();
- return NULL;
+ return nullptr;
}
static bool shutdown_health_management_thread(void *data)
{
- struct thread_notifiers *notifiers = ( thread_notifiers *) data;
+ struct thread_notifiers *notifiers = (thread_notifiers *) data;
const int write_fd = lttng_pipe_get_writefd(notifiers->quit_pipe);
return notify_thread_pipe(write_fd) == 1;
}
-bool launch_health_management_thread(void)
+bool launch_health_management_thread()
{
struct thread_notifiers *notifiers;
struct lttng_thread *thread;
- notifiers = (thread_notifiers *) zmalloc(sizeof(*notifiers));
+ notifiers = zmalloc<thread_notifiers>();
if (!notifiers) {
goto error_alloc;
}
goto error;
}
thread = lttng_thread_create("Health management",
- thread_manage_health,
- shutdown_health_management_thread,
- cleanup_health_management_thread,
- notifiers);
+ thread_manage_health,
+ shutdown_health_management_thread,
+ cleanup_health_management_thread,
+ notifiers);
if (!thread) {
goto error;
}