Backport: relayd: track the live listener socket
[lttng-tools.git] / src / bin / lttng-relayd / live.c
index e7663bfc1068a3c87015492673eafc4e5dc3423f..26f6e100149656325b1905d36960ec354d91a891 100644 (file)
@@ -418,15 +418,6 @@ error:
        return ret;
 }
 
-/*
- * Create a poll set with O_CLOEXEC and add the thread quit pipe to the set.
- */
-static
-int create_thread_poll_set(struct lttng_poll_event *events, int size)
-{
-       return create_named_thread_poll_set(events, size, "Unknown epoll");
-}
-
 /*
  * Check if the thread quit pipe was triggered.
  *
@@ -442,14 +433,40 @@ int check_thread_quit_pipe(int fd, uint32_t events)
        return 0;
 }
 
+static
+int create_sock(void *data, int *out_fd)
+{
+       int ret;
+       struct lttcomm_sock *sock = data;
+
+       ret = lttcomm_create_sock(sock);
+       if (ret < 0) {
+               goto end;
+       }
+
+       *out_fd = sock->fd;
+end:
+       return ret;
+}
+
+static
+int close_sock(void *data, int *in_fd)
+{
+       struct lttcomm_sock *sock = data;
+
+       return sock->ops->close(sock);
+}
+
 /*
  * Create and init socket from uri.
  */
 static
-struct lttcomm_sock *init_socket(struct lttng_uri *uri)
+struct lttcomm_sock *init_socket(struct lttng_uri *uri, const char *name)
 {
-       int ret;
+       int ret, sock_fd;
        struct lttcomm_sock *sock = NULL;
+       char uri_str[PATH_MAX];
+       char *formated_name = NULL;
 
        sock = lttcomm_alloc_sock_from_uri(uri);
        if (sock == NULL) {
@@ -457,11 +474,25 @@ struct lttcomm_sock *init_socket(struct lttng_uri *uri)
                goto error;
        }
 
-       ret = lttcomm_create_sock(sock);
-       if (ret < 0) {
-               goto error;
+       /*
+        * Don't fail to create the socket if the name can't be built as it is
+        * only used for debugging purposes.
+        */
+       ret = uri_to_str_url(uri, uri_str, sizeof(uri_str));
+       uri_str[sizeof(uri_str) - 1] = '\0';
+       if (ret >= 0) {
+               ret = asprintf(&formated_name, "%s socket @ %s", name,
+                               uri_str);
+               if (ret < 0) {
+                       formated_name = NULL;
+               }
        }
-       DBG("Listening on sock %d for live", sock->fd);
+
+       ret = fd_tracker_open_unsuspendable_fd(the_fd_tracker, &sock_fd,
+                       (const char **) (formated_name ? &formated_name : NULL),
+                       1, create_sock, sock);
+       free(formated_name);
+       DBG("Listening on %s socket %d", name, sock->fd);
 
        ret = sock->ops->bind(sock);
        if (ret < 0) {
@@ -500,7 +531,7 @@ void *thread_listener(void *data)
 
        health_code_update();
 
-       live_control_sock = init_socket(live_uri);
+       live_control_sock = init_socket(live_uri, "Live listener");
        if (!live_control_sock) {
                goto error_sock_control;
        }
@@ -624,7 +655,9 @@ error_testpoint:
        (void) fd_tracker_util_poll_clean(the_fd_tracker, &events);
 error_create_poll:
        if (live_control_sock->fd >= 0) {
-               ret = live_control_sock->ops->close(live_control_sock);
+               ret = fd_tracker_close_unsuspendable_fd(the_fd_tracker,
+                               &live_control_sock->fd, 1, close_sock,
+                               live_control_sock);
                if (ret) {
                        PERROR("close");
                }
@@ -1956,7 +1989,8 @@ void *thread_worker(void *data)
                goto viewer_connections_ht_error;
        }
 
-       ret = create_thread_poll_set(&events, 2);
+       ret = create_named_thread_poll_set(&events, 2,
+                       "Live viewer worker thread epoll");
        if (ret < 0) {
                goto error_poll_create;
        }
@@ -2079,7 +2113,7 @@ restart:
 
 exit:
 error:
-       lttng_poll_clean(&events);
+       (void) fd_tracker_util_poll_clean(the_fd_tracker, &events);
 
        /* Cleanup reamaining connection object. */
        rcu_read_lock();
This page took 0.027088 seconds and 5 git commands to generate.