Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure console socket buffers are properly sized #435

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/conn_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand All @@ -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)
Expand Down Expand Up @@ -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);
}
Expand Down
Loading