summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustaf Ullberg <gustaf.ullberg@gmail.com>2017-01-27 19:46:36 +0100
committerGustaf Ullberg <gustaf.ullberg@gmail.com>2017-01-27 19:46:36 +0100
commit7384f9dd420f6ec03dc312717b387b62e10a074f (patch)
tree68ab6f36314cad3e07f74856741f2693a8e97af4
parent6f886a5a13cbe1a9529595194420d717c6c53fc2 (diff)
downloaddistcc-git-7384f9dd420f6ec03dc312717b387b62e10a074f.tar.gz
Close all file descriptors in zeroconf daemon process
-rw-r--r--src/zeroconf.c12
1 files 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);