Skip to content

Commit

Permalink
connectd: use closefrom for faster forking, and ignore children
Browse files Browse the repository at this point in the history
Zombie sighting fom jb55.

Fixes: #5092
Changelog-EXPERIMENTAL: Fixed `experimental-websocket-port` not to leave zombie processes.
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Mar 16, 2022
1 parent 704162f commit 7ca0ab8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions connectd/connectd.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "config.h"
#include <ccan/array_size/array_size.h>
#include <ccan/asort/asort.h>
#include <ccan/closefrom/closefrom.h>
#include <ccan/fdpass/fdpass.h>
#include <ccan/noerr/noerr.h>
#include <ccan/tal/str/str.h>
Expand Down Expand Up @@ -41,6 +42,7 @@
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
#include <signal.h>
#include <sodium.h>
#include <sys/types.h>
#include <sys/wait.h>
Expand Down Expand Up @@ -569,7 +571,6 @@ static struct io_plan *websocket_connection_in(struct io_conn *conn,
goto close_execfail_fail;

if (childpid == 0) {
size_t max;
close(childmsg[0]);
close(execfail[0]);

Expand All @@ -582,9 +583,7 @@ static struct io_plan *websocket_connection_in(struct io_conn *conn,
goto child_errno_fail;

/* Make (fairly!) sure all other fds are closed. */
max = sysconf(_SC_OPEN_MAX);
for (size_t i = STDERR_FILENO + 1; i < max; i++)
close(i);
closefrom(STDERR_FILENO + 1);

/* Tell websocket helper what we read so far. */
execlp(daemon->websocket_helper, daemon->websocket_helper,
Expand Down Expand Up @@ -2117,6 +2116,10 @@ int main(int argc, char *argv[])
* our status_ and failed messages. */
status_setup_async(daemon->master);

/* Don't leave around websocketd zombies. Technically not portable,
* but OK for Linux and BSD, so... */
signal(SIGCHLD, SIG_IGN);

/* This streams gossip to and from gossipd */
daemon->gossipd = daemon_conn_new(daemon, GOSSIPCTL_FD,
recv_gossip, NULL,
Expand Down

0 comments on commit 7ca0ab8

Please sign in to comment.