summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn Landden <slandden@gmail.com>2018-02-25 17:35:11 -0800
committerGitHub <noreply@github.com>2018-02-25 17:35:11 -0800
commit4c799280128a113f92f58ffcfdc73d2fb251caea (patch)
treecb9f9047b79cdf42fb2983d11518f32b883699b4
parent175aa1fb79b36b9d4a9b0b7596c5e7c44ef72b98 (diff)
parent7384f9dd420f6ec03dc312717b387b62e10a074f (diff)
downloaddistcc-git-4c799280128a113f92f58ffcfdc73d2fb251caea.tar.gz
Merge pull request #209 from gustafullberg/close_all_fd
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 cdb6ea3..a0aad06 100644
--- a/src/zeroconf.c
+++ b/src/zeroconf.c
@@ -604,13 +604,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);