relayd: track the live client connections socket
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 27 Nov 2019 06:01:28 +0000 (01:01 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 30 Jan 2020 06:55:34 +0000 (01:55 -0500)
Track all live client connection socket file descritptors through the
fd-tracker. Those file descriptors, being TCP connections, are
unsuspendable.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Iacc958b0f8d168d13165e44ec8432ad29ef881f5

src/bin/lttng-relayd/live.c

index b4f3884e8a883f82c09e7b2245df944ddb8782f4..eaa4b1b73de618369a5c3e87b9fca5ba8f86ee82 100644 (file)
@@ -500,6 +500,42 @@ int close_sock(void *data, int *in_fd)
        return sock->ops->close(sock);
 }
 
+static int accept_sock(void *data, int *out_fd)
+{
+       int ret = 0;
+       /* Socks is an array of in_sock, out_sock. */
+       struct lttcomm_sock **socks = data;
+       struct lttcomm_sock *in_sock = socks[0];
+
+       socks[1] = in_sock->ops->accept(in_sock);
+       if (!socks[1]) {
+               ret = -1;
+               goto end;
+       }
+       *out_fd = socks[1]->fd;
+end:
+       return ret;
+}
+
+static
+struct lttcomm_sock *accept_live_sock(struct lttcomm_sock *listening_sock,
+               const char *name)
+{
+       int out_fd, ret;
+       struct lttcomm_sock *socks[2] = { listening_sock, NULL };
+       struct lttcomm_sock *new_sock = NULL;
+
+       ret = fd_tracker_open_unsuspendable_fd(the_fd_tracker, &out_fd,
+                       (const char **) &name, 1, accept_sock, &socks);
+       if (ret) {
+               goto end;
+       }
+       new_sock = socks[1];
+       DBG("%s accepted, socket %d", name, new_sock->fd);
+end:
+       return new_sock;
+}
+
 /*
  * Create and init socket from uri.
  */
@@ -645,7 +681,8 @@ restart:
                                struct relay_connection *new_conn;
                                struct lttcomm_sock *newsock;
 
-                               newsock = live_control_sock->ops->accept(live_control_sock);
+                               newsock = accept_live_sock(live_control_sock,
+                                               "Live socket to client");
                                if (!newsock) {
                                        PERROR("accepting control sock");
                                        goto error;
@@ -2187,7 +2224,8 @@ void cleanup_connection_pollfd(struct lttng_poll_event *events, int pollfd)
 
        (void) lttng_poll_del(events, pollfd);
 
-       ret = close(pollfd);
+       ret = fd_tracker_close_unsuspendable_fd(the_fd_tracker, &pollfd, 1,
+                       fd_tracker_util_close_fd, NULL);
        if (ret < 0) {
                ERR("Closing pollfd %d", pollfd);
        }
This page took 0.02771 seconds and 4 git commands to generate.