Skip to content

Commit

Permalink
listen_for_commands: stop leaking the control socket to forked procs
Browse files Browse the repository at this point in the history
All the "exec"d processes would get a copy of the control socket
descriptor, because of the default UNIX semantics of fd inherit across
execv().  This was easily seen on my system where an 'lsof' revealed
that all my terminals and shells had a copy.

To fix this we add the SOCK_CLOEXEC flag whilst opening the listener
socket(), avoiding this problem.  The "bar" descriptor already handles
this by setting O_CLOEXEC in its FIFO open() call.
  • Loading branch information
smemsh committed Aug 19, 2024
1 parent a5b75e2 commit b03b491
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion communications.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ listen_for_commands(void)
struct sockaddr_un sun;

if ((rp_glob_screen.control_socket_fd = socket(AF_UNIX,
SOCK_STREAM | SOCK_NONBLOCK, 0)) == -1)
SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0)) == -1)
err(1, "socket");

if (strlen(rp_glob_screen.control_socket_path) >= sizeof(sun.sun_path))
Expand Down

0 comments on commit b03b491

Please sign in to comment.