From 953f238bd2e2da0c83056801f4d17668ec309b3a Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 16 Mar 2022 11:56:41 +1030 Subject: [PATCH] connectd: use closefrom for faster forking, and ignore children Zombie sighting fom jb55. Fixes: #5092 Changelog-EXPERIMENTAL: Fixed `experimental-websocket-port` not to leave zombie processes. Signed-off-by: Rusty Russell --- connectd/connectd.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/connectd/connectd.c b/connectd/connectd.c index f3c1e1605..367253f03 100644 --- a/connectd/connectd.c +++ b/connectd/connectd.c @@ -10,6 +10,7 @@ #include "config.h" #include #include +#include #include #include #include @@ -41,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -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]); @@ -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, @@ -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,