From 7384f9dd420f6ec03dc312717b387b62e10a074f Mon Sep 17 00:00:00 2001 From: Gustaf Ullberg Date: Fri, 27 Jan 2017 19:46:36 +0100 Subject: Close all file descriptors in zeroconf daemon process --- src/zeroconf.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/zeroconf.c b/src/zeroconf.c index a06a235..baa94e3 100644 --- a/src/zeroconf.c +++ b/src/zeroconf.c @@ -602,13 +602,17 @@ int dcc_zeroconf_add_hosts(struct dcc_hostdef **ret_list, int *ret_nhosts, int n rs_log_crit("fork() failed: %s\n", strerror(errno)); goto finish; } else if (pid == 0) { - int fd; + int max_fd, fd; /* Child */ /* Close file descriptors and replace them by /dev/null */ - close(0); - close(1); - close(2); + max_fd = (int)sysconf(_SC_OPEN_MAX); + if(max_fd == -1) { + max_fd = 1024; + } + for(fd = 0; fd < max_fd; fd++) { + close(fd); + } fd = open("/dev/null", O_RDWR); assert(fd == 0); fd = dup(0); -- cgit v1.2.1