From 13a30ff79c71e7adfbc8bc9ee43ce9c031dde867 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 2 Feb 2017 14:35:45 +1030 Subject: [PATCH] subdaemon: close unused fds when creating subdaemon. Signed-off-by: Rusty Russell --- lightningd/subdaemon.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lightningd/subdaemon.c b/lightningd/subdaemon.c index 82c8f70a2..8e3864041 100644 --- a/lightningd/subdaemon.c +++ b/lightningd/subdaemon.c @@ -78,6 +78,7 @@ static int subdaemon(const char *dir, const char *name, if (childpid == 0) { int fdnum = 3; + long max; if (reqfd) close(childreq[0]); @@ -103,6 +104,11 @@ static int subdaemon(const char *dir, const char *name, goto child_errno_fail; fdnum++; } + + /* Make (fairly!) sure all other fds are closed. */ + max = sysconf(_SC_OPEN_MAX); + for (fd = fdnum; fd < max; fd++) + close(fd); execl(path_join(NULL, dir, name), name, NULL); child_errno_fail: