Standardize quit pipes behavior
[lttng-tools.git] / src / bin / lttng-sessiond / register.cpp
index 34efeac40f57729fd0811806e56cb7665847fefc..4478221ff530092307ac563fcda14157fe6818c5 100644 (file)
@@ -153,8 +153,8 @@ static void thread_init_cleanup(void *data)
  */
 static void *thread_application_registration(void *data)
 {
-       int sock = -1, i, ret, pollfd, err = -1;
-       uint32_t revents, nb_fd;
+       int sock = -1, i, ret, err = -1;
+       uint32_t nb_fd;
        struct lttng_poll_event events;
        /*
         * Gets allocated in this thread, enqueued to a global queue, dequeued
@@ -164,7 +164,7 @@ static void *thread_application_registration(void *data)
        const bool is_root = (getuid() == 0);
        struct thread_state *thread_state = (struct thread_state *) data;
        const int application_socket = thread_state->application_socket;
-       const int quit_pipe_read_fd = lttng_pipe_get_readfd(
+       const auto thread_quit_pipe_fd = lttng_pipe_get_readfd(
                        thread_state->quit_pipe);
 
        DBG("[thread] Manage application registration started");
@@ -193,7 +193,7 @@ static void *thread_application_registration(void *data)
        }
 
        /* Add the application registration socket */
-       ret = lttng_poll_add(&events, quit_pipe_read_fd, LPOLLIN | LPOLLRDHUP);
+       ret = lttng_poll_add(&events, thread_quit_pipe_fd, LPOLLIN | LPOLLRDHUP);
        if (ret < 0) {
                goto error_poll_add;
        }
@@ -229,116 +229,116 @@ static void *thread_application_registration(void *data)
                        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, closing. */
+                       if (pollfd == thread_quit_pipe_fd) {
                                err = 0;
                                goto exit;
-                       } else {
-                               /* Event on the registration socket */
-                               if (revents & LPOLLIN) {
-                                       sock = lttcomm_accept_unix_sock(application_socket);
-                                       if (sock < 0) {
-                                               goto error;
-                                       }
+                       }
 
-                                       /*
-                                        * Set socket timeout for both receiving and ending.
-                                        * app_socket_timeout is in seconds, whereas
-                                        * lttcomm_setsockopt_rcv_timeout and
-                                        * lttcomm_setsockopt_snd_timeout expect msec as
-                                        * parameter.
-                                        */
-                                       if (the_config.app_socket_timeout >= 0) {
-                                               (void) lttcomm_setsockopt_rcv_timeout(sock,
-                                                               the_config.app_socket_timeout * 1000);
-                                               (void) lttcomm_setsockopt_snd_timeout(sock,
-                                                               the_config.app_socket_timeout * 1000);
-                                       }
+                       /* Event on the registration socket. */
+                       if (revents & LPOLLIN) {
+                               sock = lttcomm_accept_unix_sock(application_socket);
+                               if (sock < 0) {
+                                       goto error;
+                               }
 
-                                       /*
-                                        * Set the CLOEXEC flag. Return code is useless because
-                                        * either way, the show must go on.
-                                        */
-                                       (void) utils_set_fd_cloexec(sock);
-
-                                       /* Create UST registration command for enqueuing */
-                                       ust_cmd = zmalloc<ust_command>();
-                                       if (ust_cmd == NULL) {
-                                               PERROR("ust command zmalloc");
-                                               ret = close(sock);
-                                               if (ret) {
-                                                       PERROR("close");
-                                               }
-                                               sock = -1;
-                                               goto error;
-                                       }
+                               /*
+                                * Set socket timeout for both receiving and ending.
+                                * app_socket_timeout is in seconds, whereas
+                                * lttcomm_setsockopt_rcv_timeout and
+                                * lttcomm_setsockopt_snd_timeout expect msec as
+                                * parameter.
+                                */
+                               if (the_config.app_socket_timeout >= 0) {
+                                       (void) lttcomm_setsockopt_rcv_timeout(sock,
+                                                       the_config.app_socket_timeout * 1000);
+                                       (void) lttcomm_setsockopt_snd_timeout(sock,
+                                                       the_config.app_socket_timeout * 1000);
+                               }
 
-                                       /*
-                                        * Using message-based transmissions to ensure we don't
-                                        * have to deal with partially received messages.
-                                        */
-                                       ret = lttng_fd_get(LTTNG_FD_APPS, 1);
-                                       if (ret < 0) {
-                                               ERR("Exhausted file descriptors allowed for applications.");
-                                               free(ust_cmd);
-                                               ret = close(sock);
-                                               if (ret) {
-                                                       PERROR("close");
-                                               }
-                                               sock = -1;
-                                               continue;
+                               /*
+                                * Set the CLOEXEC flag. Return code is useless because
+                                * either way, the show must go on.
+                                */
+                               (void) utils_set_fd_cloexec(sock);
+
+                               /* Create UST registration command for enqueuing */
+                               ust_cmd = zmalloc<ust_command>();
+                               if (ust_cmd == NULL) {
+                                       PERROR("ust command zmalloc");
+                                       ret = close(sock);
+                                       if (ret) {
+                                               PERROR("close");
                                        }
+                                       sock = -1;
+                                       goto error;
+                               }
 
-                                       health_code_update();
-                                       ret = ust_app_recv_registration(sock, &ust_cmd->reg_msg);
-                                       if (ret < 0) {
-                                               free(ust_cmd);
-                                               /* Close socket of the application. */
-                                               ret = close(sock);
-                                               if (ret) {
-                                                       PERROR("close");
-                                               }
-                                               lttng_fd_put(LTTNG_FD_APPS, 1);
-                                               sock = -1;
-                                               continue;
+                               /*
+                                * Using message-based transmissions to ensure we don't
+                                * have to deal with partially received messages.
+                                */
+                               ret = lttng_fd_get(LTTNG_FD_APPS, 1);
+                               if (ret < 0) {
+                                       ERR("Exhausted file descriptors allowed for applications.");
+                                       free(ust_cmd);
+                                       ret = close(sock);
+                                       if (ret) {
+                                               PERROR("close");
                                        }
-                                       health_code_update();
-
-                                       ust_cmd->sock = sock;
                                        sock = -1;
+                                       continue;
+                               }
 
-                                       DBG("UST registration received with pid:%d ppid:%d uid:%d"
-                                                       " gid:%d sock:%d name:%s (version %d.%d)",
-                                                       ust_cmd->reg_msg.pid, ust_cmd->reg_msg.ppid,
-                                                       ust_cmd->reg_msg.uid, ust_cmd->reg_msg.gid,
-                                                       ust_cmd->sock, ust_cmd->reg_msg.name,
-                                                       ust_cmd->reg_msg.major, ust_cmd->reg_msg.minor);
-
-                                       /*
-                                        * Lock free enqueue the registration request. The red pill
-                                        * has been taken! This apps will be part of the *system*.
-                                        */
-                                       cds_wfcq_head_ptr_t head;
-                                       head.h = &thread_state->ust_cmd_queue->head;
-                                       cds_wfcq_enqueue(head,
-                                                       &thread_state->ust_cmd_queue->tail,
-                                                       &ust_cmd->node);
-
-                                       /*
-                                        * Wake the registration queue futex. Implicit memory
-                                        * barrier with the exchange in cds_wfcq_enqueue.
-                                        */
-                                       futex_nto1_wake(&thread_state->ust_cmd_queue->futex);
-                               } else if (revents & (LPOLLERR | LPOLLHUP | LPOLLRDHUP)) {
-                                       ERR("Register apps socket poll error");
-                                       goto error;
-                               } else {
-                                       ERR("Unexpected poll events %u for sock %d", revents, pollfd);
-                                       goto error;
+                               health_code_update();
+                               ret = ust_app_recv_registration(sock, &ust_cmd->reg_msg);
+                               if (ret < 0) {
+                                       free(ust_cmd);
+                                       /* Close socket of the application. */
+                                       ret = close(sock);
+                                       if (ret) {
+                                               PERROR("close");
+                                       }
+                                       lttng_fd_put(LTTNG_FD_APPS, 1);
+                                       sock = -1;
+                                       continue;
                                }
+                               health_code_update();
+
+                               ust_cmd->sock = sock;
+                               sock = -1;
+
+                               DBG("UST registration received with pid:%d ppid:%d uid:%d"
+                                               " gid:%d sock:%d name:%s (version %d.%d)",
+                                               ust_cmd->reg_msg.pid, ust_cmd->reg_msg.ppid,
+                                               ust_cmd->reg_msg.uid, ust_cmd->reg_msg.gid,
+                                               ust_cmd->sock, ust_cmd->reg_msg.name,
+                                               ust_cmd->reg_msg.major, ust_cmd->reg_msg.minor);
+
+                               /*
+                                * Lock free enqueue the registration request. The red pill
+                                * has been taken! This apps will be part of the *system*.
+                                */
+                               cds_wfcq_head_ptr_t head;
+                               head.h = &thread_state->ust_cmd_queue->head;
+                               cds_wfcq_enqueue(head,
+                                               &thread_state->ust_cmd_queue->tail,
+                                               &ust_cmd->node);
+
+                               /*
+                                * Wake the registration queue futex. Implicit memory
+                                * barrier with the exchange in cds_wfcq_enqueue.
+                                */
+                               futex_nto1_wake(&thread_state->ust_cmd_queue->futex);
+                       } else if (revents & (LPOLLERR | LPOLLHUP | LPOLLRDHUP)) {
+                               ERR("Register apps socket poll error");
+                               goto error;
+                       } else {
+                               ERR("Unexpected poll events %u for sock %d", revents, pollfd);
+                               goto error;
                        }
                }
        }
This page took 0.026133 seconds and 4 git commands to generate.