diff options
author | Shawn Landden <slandden@gmail.com> | 2018-02-25 17:35:11 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-25 17:35:11 -0800 |
commit | 4c799280128a113f92f58ffcfdc73d2fb251caea (patch) | |
tree | cb9f9047b79cdf42fb2983d11518f32b883699b4 | |
parent | 175aa1fb79b36b9d4a9b0b7596c5e7c44ef72b98 (diff) | |
parent | 7384f9dd420f6ec03dc312717b387b62e10a074f (diff) | |
download | distcc-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.c | 12 |
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); |