summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Kelley <simon@thekelleys.org.uk>2012-01-18 16:07:21 +0000
committerSimon Kelley <simon@thekelleys.org.uk>2012-01-18 16:07:21 +0000
commita2761754da41275e556c1f1a15eb492108e8d619 (patch)
tree8636e4f44e7e0b6d2682857afcec0be393dacdb8
parent805a11345c452efcb17286a265ce192ff32beb07 (diff)
downloaddnsmasq-a2761754da41275e556c1f1a15eb492108e8d619.tar.gz
Fix problem if dnsmasq is started without the stdin,v2.60test10
stdout and stderr file descriptors open. This can manifest itself as 100% CPU use. Thanks to Chris Moore for finding this.
-rw-r--r--CHANGELOG8
-rw-r--r--src/dnsmasq.c11
2 files changed, 18 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG
index b33bf5a..0950191 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -29,6 +29,14 @@ version 2.60
Determine VERSION automatically based on git magic:
release tags or hash values.
+ Improve start-up speed when reading large hosts files
+ containing many distinct addresses.
+
+ Fix problem if dnsmasq is started without the stdin,
+ stdout and stderr file descriptors open. This can manifest
+ itself as 100% CPU use. Thanks to Chris Moore for finding
+ this.
+
version 2.59
Fix regression in 2.58 which caused failure to start up
diff --git a/src/dnsmasq.c b/src/dnsmasq.c
index 0b17df3..f8b3d07 100644
--- a/src/dnsmasq.c
+++ b/src/dnsmasq.c
@@ -92,10 +92,19 @@ int main (int argc, char **argv)
}
#endif
- /* Close any file descriptors we inherited apart from std{in|out|err} */
+ /* Close any file descriptors we inherited apart from std{in|out|err}
+
+ Ensure that at least stdin, stdout and stderr (fd 0, 1, 2) exist,
+ otherwise file descriptors we create can end up being 0, 1, or 2
+ and then get accidentally closed later when we make 0, 1, and 2
+ open to /dev/null. Normally we'll be started with 0, 1 and 2 open,
+ but it's not guaranteed. By opening /dev/null three times, we
+ ensure that we're not using those fds for real stuff. */
for (i = 0; i < max_fd; i++)
if (i != STDOUT_FILENO && i != STDERR_FILENO && i != STDIN_FILENO)
close(i);
+ else
+ open("/dev/null", O_RDWR);
#ifdef HAVE_LINUX_NETWORK
netlink_init();