Clean-up: modernize pretty_xml.cpp
[lttng-tools.git] / src / bin / lttng-consumerd / health-consumerd.cpp
index ec30af5ddc1f1fd5517365bd94622da89278c17c..d0a6ce14fd451e35cc3036533dc8fcb59bc71352 100644 (file)
@@ -6,59 +6,44 @@
  */
 
 #define _LGPL_SOURCE
+#include "health-consumerd.hpp"
+#include "lttng-consumerd.hpp"
+
+#include <common/common.hpp>
+#include <common/compat/poll.hpp>
+#include <common/consumer/consumer-timer.hpp>
+#include <common/consumer/consumer.hpp>
+#include <common/defaults.hpp>
+#include <common/sessiond-comm/sessiond-comm.hpp>
+#include <common/utils.hpp>
+
 #include <fcntl.h>
 #include <getopt.h>
 #include <grp.h>
+#include <inttypes.h>
 #include <limits.h>
+#include <poll.h>
 #include <pthread.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/ipc.h>
+#include <sys/mman.h>
 #include <sys/resource.h>
 #include <sys/shm.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/types.h>
-#include <urcu/list.h>
-#include <poll.h>
+#include <ulimit.h>
 #include <unistd.h>
-#include <sys/mman.h>
 #include <urcu/compiler.h>
-#include <ulimit.h>
-#include <inttypes.h>
-
-#include <common/defaults.h>
-#include <common/common.h>
-#include <common/consumer/consumer.h>
-#include <common/consumer/consumer-timer.h>
-#include <common/compat/poll.h>
-#include <common/sessiond-comm/sessiond-comm.h>
-#include <common/utils.h>
-
-#include "lttng-consumerd.h"
-#include "health-consumerd.h"
+#include <urcu/list.h>
 
 /* Global health check unix path */
 static char health_unix_sock_path[PATH_MAX];
 
-int health_quit_pipe[2];
-
-/*
- * Check if the thread quit pipe was triggered.
- *
- * Return 1 if it was triggered else 0;
- */
-static
-int check_health_quit_pipe(int fd, uint32_t events)
-{
-       if (fd == health_quit_pipe[0] && (events & LPOLLIN)) {
-               return 1;
-       }
-
-       return 0;
-}
+int health_quit_pipe[2] = { -1, -1 };
 
 /*
  * Send data on a unix socket using the liblttsessiondcomm API.
@@ -75,8 +60,7 @@ static int send_unix_sock(int sock, void *buf, size_t len)
        return lttcomm_send_unix_sock(sock, buf, len);
 }
 
-static
-int setup_health_path(void)
+static int setup_health_path()
 {
        int is_root, ret = 0;
        enum lttng_consumer_type type;
@@ -91,16 +75,19 @@ int setup_health_path(void)
                }
                switch (type) {
                case LTTNG_CONSUMER_KERNEL:
-                       snprintf(health_unix_sock_path, sizeof(health_unix_sock_path),
-                               DEFAULT_GLOBAL_KCONSUMER_HEALTH_UNIX_SOCK);
+                       snprintf(health_unix_sock_path,
+                                sizeof(health_unix_sock_path),
+                                DEFAULT_GLOBAL_KCONSUMER_HEALTH_UNIX_SOCK);
                        break;
                case LTTNG_CONSUMER64_UST:
-                       snprintf(health_unix_sock_path, sizeof(health_unix_sock_path),
-                               DEFAULT_GLOBAL_USTCONSUMER64_HEALTH_UNIX_SOCK);
+                       snprintf(health_unix_sock_path,
+                                sizeof(health_unix_sock_path),
+                                DEFAULT_GLOBAL_USTCONSUMER64_HEALTH_UNIX_SOCK);
                        break;
                case LTTNG_CONSUMER32_UST:
-                       snprintf(health_unix_sock_path, sizeof(health_unix_sock_path),
-                               DEFAULT_GLOBAL_USTCONSUMER32_HEALTH_UNIX_SOCK);
+                       snprintf(health_unix_sock_path,
+                                sizeof(health_unix_sock_path),
+                                DEFAULT_GLOBAL_USTCONSUMER32_HEALTH_UNIX_SOCK);
                        break;
                default:
                        ret = -EINVAL;
@@ -108,7 +95,7 @@ int setup_health_path(void)
                }
        } else {
                home_path = utils_get_home_dir();
-               if (home_path == NULL) {
+               if (home_path == nullptr) {
                        /* TODO: Add --socket PATH option */
                        ERR("Can't get HOME directory for sockets creation.");
                        ret = -EPERM;
@@ -121,16 +108,22 @@ int setup_health_path(void)
                }
                switch (type) {
                case LTTNG_CONSUMER_KERNEL:
-                       snprintf(health_unix_sock_path, sizeof(health_unix_sock_path),
-                               DEFAULT_HOME_KCONSUMER_HEALTH_UNIX_SOCK, home_path);
+                       snprintf(health_unix_sock_path,
+                                sizeof(health_unix_sock_path),
+                                DEFAULT_HOME_KCONSUMER_HEALTH_UNIX_SOCK,
+                                home_path);
                        break;
                case LTTNG_CONSUMER64_UST:
-                       snprintf(health_unix_sock_path, sizeof(health_unix_sock_path),
-                               DEFAULT_HOME_USTCONSUMER64_HEALTH_UNIX_SOCK, home_path);
+                       snprintf(health_unix_sock_path,
+                                sizeof(health_unix_sock_path),
+                                DEFAULT_HOME_USTCONSUMER64_HEALTH_UNIX_SOCK,
+                                home_path);
                        break;
                case LTTNG_CONSUMER32_UST:
-                       snprintf(health_unix_sock_path, sizeof(health_unix_sock_path),
-                               DEFAULT_HOME_USTCONSUMER32_HEALTH_UNIX_SOCK, home_path);
+                       snprintf(health_unix_sock_path,
+                                sizeof(health_unix_sock_path),
+                                DEFAULT_HOME_USTCONSUMER32_HEALTH_UNIX_SOCK,
+                                home_path);
                        break;
                default:
                        ret = -EINVAL;
@@ -144,10 +137,10 @@ end:
 /*
  * Thread managing health check socket.
  */
-void *thread_manage_health(void *data)
+void *thread_manage_health_consumerd(void *data __attribute__((unused)))
 {
-       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;
@@ -189,8 +182,7 @@ void *thread_manage_health(void *data)
                        goto error;
                }
 
-               ret = chmod(health_unix_sock_path,
-                               S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
+               ret = chmod(health_unix_sock_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
                if (ret < 0) {
                        ERR("Unable to set permissions on %s", health_unix_sock_path);
                        PERROR("chmod");
@@ -232,11 +224,11 @@ void *thread_manage_health(void *data)
        cmm_smp_mb__before_uatomic_dec();
        uatomic_dec(&lttng_consumer_ready);
 
-       while (1) {
+       while (true) {
                DBG("Health check ready");
 
                /* Inifinite blocking call, waiting for transmission */
-restart:
+       restart:
                ret = lttng_poll_wait(&events, -1);
                if (ret < 0) {
                        /*
@@ -252,20 +244,20 @@ restart:
 
                for (i = 0; i < nb_fd; i++) {
                        /* Fetch once the poll data */
-                       revents = LTTNG_POLL_GETEV(&events, i);
-                       pollfd = LTTNG_POLL_GETFD(&events, i);
+                       const auto revents = LTTNG_POLL_GETEV(&events, i);
+                       const auto pollfd = LTTNG_POLL_GETFD(&events, i);
 
-                       /* Thread quit pipe has been closed. Killing thread. */
-                       ret = check_health_quit_pipe(pollfd, revents);
-                       if (ret) {
+                       /* Activity on health quit pipe, exiting. */
+                       if (pollfd == health_quit_pipe[0]) {
+                               DBG("Activity on health quit pipe");
                                err = 0;
                                goto exit;
                        }
 
                        /* Event on the registration socket */
                        if (pollfd == sock) {
-                               if (revents & (LPOLLERR | LPOLLHUP | LPOLLRDHUP)
-                                               && !(revents & LPOLLIN)) {
+                               if (revents & (LPOLLERR | LPOLLHUP | LPOLLRDHUP) &&
+                                   !(revents & LPOLLIN)) {
                                        ERR("Health socket poll error");
                                        goto error;
                                }
@@ -284,7 +276,7 @@ restart:
                (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);
@@ -342,5 +334,5 @@ error:
        lttng_poll_clean(&events);
 
        rcu_unregister_thread();
-       return NULL;
+       return nullptr;
 }
This page took 0.026683 seconds and 4 git commands to generate.