mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
subdaemon: close unused fds when creating subdaemon.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -78,6 +78,7 @@ static int subdaemon(const char *dir, const char *name,
|
|||||||
|
|
||||||
if (childpid == 0) {
|
if (childpid == 0) {
|
||||||
int fdnum = 3;
|
int fdnum = 3;
|
||||||
|
long max;
|
||||||
|
|
||||||
if (reqfd)
|
if (reqfd)
|
||||||
close(childreq[0]);
|
close(childreq[0]);
|
||||||
@@ -103,6 +104,11 @@ static int subdaemon(const char *dir, const char *name,
|
|||||||
goto child_errno_fail;
|
goto child_errno_fail;
|
||||||
fdnum++;
|
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);
|
execl(path_join(NULL, dir, name), name, NULL);
|
||||||
|
|
||||||
child_errno_fail:
|
child_errno_fail:
|
||||||
|
|||||||
Reference in New Issue
Block a user