Backport: relayd: track the control listener socket
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 28 Jun 2018 04:15:40 +0000 (00:15 -0400)
committerJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Fri, 21 Sep 2018 04:00:52 +0000 (00:00 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-relayd/main.c

index 36dfc7fb4b88eeee96741178a2d72b87fcfcf720..ff135c645ffb158d31a919d5ef882a5023a9fb07 100644 (file)
@@ -840,13 +840,38 @@ static 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 *relay_socket_create(struct lttng_uri *uri)
+static struct lttcomm_sock *relay_socket_create(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) {
@@ -854,11 +879,25 @@ static struct lttcomm_sock *relay_socket_create(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", 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) {
@@ -896,12 +935,12 @@ static void *relay_thread_listener(void *data)
 
        health_code_update();
 
-       control_sock = relay_socket_create(control_uri);
+       control_sock = relay_socket_create(control_uri, "Control listener");
        if (!control_sock) {
                goto error_sock_control;
        }
 
-       data_sock = relay_socket_create(data_uri);
+       data_sock = relay_socket_create(data_uri, NULL);
        if (!data_sock) {
                goto error_sock_relay;
        }
@@ -1063,7 +1102,9 @@ error_create_poll:
        lttcomm_destroy_sock(data_sock);
 error_sock_relay:
        if (control_sock->fd >= 0) {
-               ret = control_sock->ops->close(control_sock);
+               ret = fd_tracker_close_unsuspendable_fd(the_fd_tracker,
+                               &control_sock->fd, 1, close_sock,
+                               control_sock);
                if (ret) {
                        PERROR("close");
                }
This page took 0.029992 seconds and 5 git commands to generate.