From fa67ce6d19c41d9610756ed306d257d9e6852943 Mon Sep 17 00:00:00 2001 From: Doug Rabson Date: Thu, 6 Jul 2023 14:09:28 +0100 Subject: [PATCH] ensure console socket buffers are properly sized On FreeBSD, the default socket buffer size for unix domain sockets is just 8192 which is too small for largest message used on the console socket which is 8193. This causes output for processes which emit large amounts of data to be lost on FreeBSD (for an example, see podman's 'podman exec/run - missing output' system test). To avoid the problem, this commit increases the buffer sizes to CONN_SOCK_BUF_SIZE (32768) which allows for several max-sized messages to be in-flight. Signed-off-by: Doug Rabson --- src/conn_sock.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/conn_sock.c b/src/conn_sock.c index 2550af09..4bbe24f0 100644 --- a/src/conn_sock.c +++ b/src/conn_sock.c @@ -110,6 +110,14 @@ static void bind_relative_to_dir(int dir_fd, int sock_fd, const char *path) if (bind(sock_fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) pexit("Failed to bind to console-socket"); } + +static void set_socket_buffers(G_GNUC_UNUSED int fd) +{ + /* + * Nothing needed here for Linux - the default buffer sizes for unix domain sockets are large enough. + */ +} + #endif #ifdef __FreeBSD__ @@ -135,6 +143,18 @@ static void bind_relative_to_dir(int dir_fd, int sock_fd, const char *path) if (fchmodat(dir_fd, addr.sun_path, 0700, AT_SYMLINK_NOFOLLOW)) pexit("Failed to change console-socket permissions"); } + +static void set_socket_buffers(int fd) +{ + int sz = CONN_SOCK_BUF_SIZE; + if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &sz, sizeof(sz))) { + nwarn("failed to set socket receive buffer size"); + } + if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &sz, sizeof(sz))) { + nwarn("failed to set socket send buffer size"); + } +} + #endif static char *setup_socket(int *fd, const char *path) @@ -357,6 +377,7 @@ static gboolean attach_cb(int fd, G_GNUC_UNUSED GIOCondition condition, gpointer nwarn("Failed to accept client connection on attach socket"); } else { struct remote_sock_s *remote_sock; + set_socket_buffers(new_fd); if (srcsock->dest->readers == NULL) { srcsock->dest->readers = g_ptr_array_new_with_free_func(free); }