Run clang-format on the whole tree
[lttng-tools.git] / src / bin / lttng-sessiond / notify-apps.cpp
index 8e238e5c15ba4a68a471979fead43753061954b5..5d67a914f8ecbc6abefba99b8a6709bd33efd61c 100644 (file)
@@ -7,41 +7,42 @@
 
 #define _LGPL_SOURCE
 
-#include <common/common.hpp>
-#include <common/utils.hpp>
-
 #include "fd-limit.hpp"
+#include "health-sessiond.hpp"
 #include "lttng-sessiond.hpp"
 #include "notify-apps.hpp"
-#include "health-sessiond.hpp"
 #include "testpoint.hpp"
-#include "utils.hpp"
 #include "thread.hpp"
+#include "utils.hpp"
 
+#include <common/common.hpp>
+#include <common/utils.hpp>
+
+namespace {
 struct thread_notifiers {
        struct lttng_pipe *quit_pipe;
        int apps_cmd_notify_pipe_read_fd;
 };
+} /* namespace */
 
 /*
  * This thread manage application notify communication.
  */
 static void *thread_application_notification(void *data)
 {
-       int i, ret, pollfd, err = -1;
+       int i, ret, err = -1;
        ssize_t size_ret;
-       uint32_t revents, nb_fd;
+       uint32_t nb_fd;
        struct lttng_poll_event events;
        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("[ust-thread] Manage application notify command");
 
        rcu_register_thread();
        rcu_thread_online();
 
-       health_register(the_health_sessiond,
-                       HEALTH_SESSIOND_TYPE_APP_MANAGE_NOTIFY);
+       health_register(the_health_sessiond, HEALTH_SESSIOND_TYPE_APP_MANAGE_NOTIFY);
 
        if (testpoint(sessiond_thread_app_manage_notify)) {
                goto error_testpoint;
@@ -55,14 +56,13 @@ static void *thread_application_notification(void *data)
        }
 
        /* Add notify pipe to the pollset. */
-       ret = lttng_poll_add(&events, notifiers->apps_cmd_notify_pipe_read_fd,
-                       LPOLLIN | LPOLLERR | LPOLLHUP | LPOLLRDHUP);
+       ret = lttng_poll_add(
+               &events, notifiers->apps_cmd_notify_pipe_read_fd, LPOLLIN | LPOLLRDHUP);
        if (ret < 0) {
                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;
        }
@@ -73,11 +73,11 @@ static void *thread_application_notification(void *data)
                DBG3("[ust-thread] Manage notify polling");
 
                /* Inifinite blocking call, waiting for transmission */
-restart:
+       restart:
                health_poll_entry();
                ret = lttng_poll_wait(&events, -1);
                DBG3("[ust-thread] Manage notify return from poll on %d fds",
-                               LTTNG_POLL_GETNB(&events));
+                    LTTNG_POLL_GETNB(&events));
                health_poll_exit();
                if (ret < 0) {
                        /*
@@ -95,33 +95,38 @@ restart:
                        health_code_update();
 
                        /* 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. */
-                       if (pollfd == quit_pipe_read_fd) {
+                       /* Activity on thread quit pipe, exiting. */
+                       if (pollfd == thread_quit_pipe_fd) {
+                               DBG("Activity on thread quit pipe");
                                err = 0;
                                goto exit;
-                       } else if (pollfd == notifiers->apps_cmd_notify_pipe_read_fd) {
+                       }
+
+                       if (pollfd == notifiers->apps_cmd_notify_pipe_read_fd) {
                                /* Inspect the apps cmd pipe */
                                int sock;
 
                                if (revents & LPOLLIN) {
                                        /* Get socket from dispatch thread. */
-                                       size_ret = lttng_read(notifiers->apps_cmd_notify_pipe_read_fd,
-                                                       &sock, sizeof(sock));
+                                       size_ret =
+                                               lttng_read(notifiers->apps_cmd_notify_pipe_read_fd,
+                                                          &sock,
+                                                          sizeof(sock));
                                        if (size_ret < sizeof(sock)) {
                                                PERROR("read apps notify pipe");
                                                goto error;
                                        }
                                        health_code_update();
 
-                                       ret = lttng_poll_add(&events, sock,
-                                                       LPOLLIN | LPOLLERR | LPOLLHUP | LPOLLRDHUP);
+                                       ret = lttng_poll_add(&events, sock, LPOLLIN | LPOLLRDHUP);
                                        if (ret < 0) {
                                                /*
-                                                * It's possible we've reached the max poll fd allowed.
-                                                * Let's close the socket but continue normal execution.
+                                                * It's possible we've reached the max poll fd
+                                                * allowed. Let's close the socket but continue
+                                                * normal execution.
                                                 */
                                                ret = close(sock);
                                                if (ret) {
@@ -135,7 +140,9 @@ restart:
                                        ERR("Apps notify command pipe error");
                                        goto error;
                                } else {
-                                       ERR("Unexpected poll events %u for sock %d", revents, pollfd);
+                                       ERR("Unexpected poll events %u for sock %d",
+                                           revents,
+                                           pollfd);
                                        goto error;
                                }
                        } else {
@@ -152,7 +159,8 @@ restart:
                                                        goto error;
                                                }
 
-                                               /* The socket is closed after a grace period here. */
+                                               /* The socket is closed after a grace period here.
+                                                */
                                                ust_app_notify_sock_unregister(pollfd);
                                        }
                                } else if (revents & (LPOLLERR | LPOLLHUP | LPOLLRDHUP)) {
@@ -165,7 +173,9 @@ restart:
                                        /* The socket is closed after a grace period here. */
                                        ust_app_notify_sock_unregister(pollfd);
                                } else {
-                                       ERR("Unexpected poll events %u for sock %d", revents, pollfd);
+                                       ERR("Unexpected poll events %u for sock %d",
+                                           revents,
+                                           pollfd);
                                        goto error;
                                }
                                health_code_update();
@@ -212,7 +222,7 @@ bool launch_application_notification_thread(int apps_cmd_notify_pipe_read_fd)
        struct thread_notifiers *notifiers;
        struct lttng_pipe *quit_pipe;
 
-       notifiers = (thread_notifiers *) zmalloc(sizeof(*notifiers));
+       notifiers = zmalloc<thread_notifiers>();
        if (!notifiers) {
                goto error_alloc;
        }
@@ -225,10 +235,10 @@ bool launch_application_notification_thread(int apps_cmd_notify_pipe_read_fd)
        notifiers->quit_pipe = quit_pipe;
 
        thread = lttng_thread_create("Application notification",
-                       thread_application_notification,
-                       shutdown_application_notification_thread,
-                       cleanup_application_notification_thread,
-                       notifiers);
+                                    thread_application_notification,
+                                    shutdown_application_notification_thread,
+                                    cleanup_application_notification_thread,
+                                    notifiers);
        if (!thread) {
                goto error;
        }
This page took 0.02509 seconds and 4 git commands to generate.