Clean-up: modernize pretty_xml.cpp
[lttng-tools.git] / src / bin / lttng-sessiond / manage-apps.cpp
index 93d3b93cc12a0699b724ca7f36966ca7539c4640..ef55b452e8b54b63a37366fcd25a5a8d39089a4a 100644 (file)
@@ -7,16 +7,20 @@
  *
  */
 
+#include "health-sessiond.hpp"
 #include "manage-apps.hpp"
 #include "testpoint.hpp"
-#include "health-sessiond.hpp"
-#include "utils.hpp"
 #include "thread.hpp"
+#include "utils.hpp"
 
+#include <fcntl.h>
+
+namespace {
 struct thread_notifiers {
        struct lttng_pipe *quit_pipe;
        int apps_cmd_pipe_read_fd;
 };
+} /* namespace */
 
 static void cleanup_application_management_thread(void *data)
 {
@@ -33,7 +37,7 @@ static void cleanup_application_management_thread(void *data)
  *
  * At that point, it flushes the data (tracing and metadata) associated
  * with this application and tears down ust app sessions and other
- * associated data structures through ust_app_unregister().
+ * associated data structures through ust_app_unregister_by_socket().
  *
  * Note that this thread never sends commands to the applications
  * through the command sockets; it merely listens for hang-ups
@@ -41,13 +45,12 @@ static void cleanup_application_management_thread(void *data)
  */
 static void *thread_application_management(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("[thread] Manage application started");
 
@@ -67,13 +70,12 @@ static void *thread_application_management(void *data)
                goto error_poll_create;
        }
 
-       ret = lttng_poll_add(&events, notifiers->apps_cmd_pipe_read_fd,
-                       LPOLLIN | LPOLLRDHUP);
+       ret = lttng_poll_add(&events, notifiers->apps_cmd_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;
        }
@@ -84,15 +86,14 @@ static void *thread_application_management(void *data)
 
        health_code_update();
 
-       while (1) {
+       while (true) {
                DBG("Apps thread polling");
 
                /* Inifinite blocking call, waiting for transmission */
        restart:
                health_poll_entry();
                ret = lttng_poll_wait(&events, -1);
-               DBG("Apps thread return from poll on %d fds",
-                               LTTNG_POLL_GETNB(&events));
+               DBG("Apps thread return from poll on %d fds", LTTNG_POLL_GETNB(&events));
                health_poll_exit();
                if (ret < 0) {
                        /*
@@ -108,23 +109,27 @@ static void *thread_application_management(void *data)
 
                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);
 
                        health_code_update();
 
-                       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_pipe_read_fd) {
+                       }
+
+                       if (pollfd == notifiers->apps_cmd_pipe_read_fd) {
                                /* Inspect the apps cmd pipe */
                                if (revents & LPOLLIN) {
                                        int sock;
 
                                        /* Empty pipe */
-                                       size_ret = lttng_read(
-                                                       notifiers->apps_cmd_pipe_read_fd,
-                                                       &sock, sizeof(sock));
+                                       size_ret = lttng_read(notifiers->apps_cmd_pipe_read_fd,
+                                                             &sock,
+                                                             sizeof(sock));
                                        if (size_ret < sizeof(sock)) {
                                                PERROR("read apps cmd pipe");
                                                goto error;
@@ -136,8 +141,7 @@ static void *thread_application_management(void *data)
                                         * Since this is a command socket (write then read),
                                         * we only monitor the error events of the socket.
                                         */
-                                       ret = lttng_poll_add(&events, sock,
-                                                       LPOLLERR | LPOLLHUP | LPOLLRDHUP);
+                                       ret = lttng_poll_add(&events, sock, LPOLLRDHUP);
                                        if (ret < 0) {
                                                goto error;
                                        }
@@ -163,9 +167,11 @@ static void *thread_application_management(void *data)
                                        }
 
                                        /* Socket closed on remote end. */
-                                       ust_app_unregister(pollfd);
+                                       ust_app_unregister_by_socket(pollfd);
                                } else {
-                                       ERR("Unexpected poll events %u for sock %d", revents, pollfd);
+                                       ERR("Unexpected poll events %u for sock %d",
+                                           revents,
+                                           pollfd);
                                        goto error;
                                }
                        }
@@ -194,7 +200,7 @@ error_testpoint:
        DBG("Application communication apps thread cleanup complete");
        rcu_thread_offline();
        rcu_unregister_thread();
-       return NULL;
+       return nullptr;
 }
 
 static bool shutdown_application_management_thread(void *data)
@@ -208,7 +214,7 @@ static bool shutdown_application_management_thread(void *data)
 bool launch_application_management_thread(int apps_cmd_pipe_read_fd)
 {
        struct lttng_pipe *quit_pipe;
-       struct thread_notifiers *notifiers = NULL;
+       struct thread_notifiers *notifiers = nullptr;
        struct lttng_thread *thread;
 
        notifiers = zmalloc<thread_notifiers>();
@@ -223,10 +229,10 @@ bool launch_application_management_thread(int apps_cmd_pipe_read_fd)
        notifiers->apps_cmd_pipe_read_fd = apps_cmd_pipe_read_fd;
 
        thread = lttng_thread_create("UST application management",
-                       thread_application_management,
-                       shutdown_application_management_thread,
-                       cleanup_application_management_thread,
-                       notifiers);
+                                    thread_application_management,
+                                    shutdown_application_management_thread,
+                                    cleanup_application_management_thread,
+                                    notifiers);
        if (!thread) {
                goto error;
        }
This page took 0.026483 seconds and 4 git commands to generate.