relayd: track relayd data connection sockets
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 28 Jun 2018 05:16:43 +0000 (01:16 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 30 Jan 2020 19:46:10 +0000 (14:46 -0500)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I510f2ca49995e56735408d14562cf1d45fef842e

src/bin/lttng-relayd/main.c

index 63927bf9f73b8cd008495d4a4dde9e1f1cc1b4a1..4410f4b6997bea79f0a753e9aaf119198eb34fd6 100644 (file)
@@ -977,6 +977,23 @@ static 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;
+}
+
 /*
  * Create and init socket from uri.
  */
@@ -1035,6 +1052,27 @@ error:
        return NULL;
 }
 
+static
+struct lttcomm_sock *accept_relayd_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;
+}
+
 /*
  * This thread manages the listening for new connections on the network
  */
@@ -1133,14 +1171,13 @@ restart:
                                 */
                                int val = 1;
                                struct relay_connection *new_conn;
-                               struct lttcomm_sock *newsock;
+                               struct lttcomm_sock *newsock = NULL;
                                enum connection_type type;
 
                                if (pollfd == data_sock->fd) {
                                        type = RELAY_DATA;
-                                       newsock = data_sock->ops->accept(data_sock);
-                                       DBG("Relay data connection accepted, socket %d",
-                                                       newsock->fd);
+                                       newsock = accept_relayd_sock(data_sock,
+                                                       "Data socket to relayd");
                                } else {
                                        assert(pollfd == control_sock->fd);
                                        type = RELAY_CONTROL;
@@ -3722,7 +3759,8 @@ static void cleanup_connection_pollfd(struct lttng_poll_event *events, int pollf
 
        (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.027224 seconds and 4 git commands to generate.