Backport: relayd: track the live listener socket
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 28 Jun 2018 04:14:52 +0000 (00:14 -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/live.c

index 4f14459d46a61545cd5c05ab75fd012a3de4cca2..f14b907cea778fdb546fefa7c23ab9a52a002e63 100644 (file)
@@ -433,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) {
@@ -448,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) {
@@ -491,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;
        }
@@ -615,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");
                }
This page took 0.029481 seconds and 5 git commands to generate.