import of dnsmasq-2.32.tar.gz

This commit is contained in:
Simon Kelley
2006-06-09 21:02:31 +01:00
parent 7cebd20fe7
commit 849a8357ba
24 changed files with 6621 additions and 4429 deletions

View File

@@ -128,7 +128,6 @@ int main (int argc, char **argv)
else if (!(daemon->listeners = create_wildcard_listeners(daemon->port)))
die(_("failed to create listening socket: %s"), NULL);
forward_init(1);
cache_init(daemon->cachesize, daemon->options & OPT_LOG);
now = dnsmasq_time();
@@ -167,6 +166,7 @@ int main (int argc, char **argv)
if (daemon->query_port)
{
union mysockaddr addr;
memset(&addr, 0, sizeof(addr));
addr.in.sin_family = AF_INET;
addr.in.sin_addr.s_addr = INADDR_ANY;
addr.in.sin_port = htons(daemon->query_port);
@@ -175,11 +175,10 @@ int main (int argc, char **argv)
#endif
allocate_sfd(&addr, &daemon->sfds);
#ifdef HAVE_IPV6
memset(&addr, 0, sizeof(addr));
addr.in6.sin6_family = AF_INET6;
addr.in6.sin6_addr = in6addr_any;
addr.in6.sin6_port = htons(daemon->query_port);
addr.in6.sin6_flowinfo = 0;
addr.in6.sin6_scope_id = 0;
#ifdef HAVE_SOCKADDR_SA_LEN
addr.in6.sin6_len = sizeof(struct sockaddr_in6);
#endif
@@ -197,7 +196,19 @@ int main (int argc, char **argv)
sig = SIGHUP;
write(pipewrite, &sig, 1);
if (!(daemon->options & OPT_DEBUG))
if (daemon->options & OPT_DEBUG)
{
#ifdef LOG_PERROR
openlog("dnsmasq", LOG_PERROR, daemon->log_fac);
#else
openlog("dnsmasq", 0, daemon->log_fac);
#endif
#ifdef HAVE_LINUX_NETWORK
prctl(PR_SET_DUMPABLE, 1);
#endif
}
else
{
FILE *pidfile;
struct passwd *ent_pw = daemon->username ? getpwnam(daemon->username) : NULL;
@@ -322,16 +333,10 @@ int main (int argc, char **argv)
capset(hdr, data);
#endif
}
}
#ifdef HAVE_LINUX_NETWORK
else
prctl(PR_SET_DUMPABLE, 1);
#endif
openlog("dnsmasq",
DNSMASQ_LOG_OPT(daemon->options & OPT_DEBUG),
DNSMASQ_LOG_FAC(daemon->options & OPT_DEBUG));
openlog("dnsmasq", LOG_PID, daemon->log_fac);
}
if (daemon->cachesize != 0)
syslog(LOG_INFO, _("started, version %s cachesize %d"), VERSION, daemon->cachesize);
else
@@ -444,7 +449,7 @@ int main (int argc, char **argv)
/* Check for changes to resolv files once per second max. */
/* Don't go silent for long periods if the clock goes backwards. */
if (last == 0 || difftime(now, last) > 1.0 || difftime(now, last) < 1.0)
if (last == 0 || difftime(now, last) > 1.0 || difftime(now, last) < -1.0)
{
last = now;
@@ -472,14 +477,11 @@ int main (int argc, char **argv)
else
{
res->logged = 0;
if (statbuf.st_mtime != res->mtime)
if (statbuf.st_mtime != res->mtime &&
difftime(statbuf.st_mtime, last_change) > 0.0)
{
res->mtime = statbuf.st_mtime;
if (difftime(res->mtime, last_change) > 0.0)
{
last_change = res->mtime;
latest = res;
}
last_change = statbuf.st_mtime;
latest = res;
}
}
res = res->next;
@@ -487,8 +489,19 @@ int main (int argc, char **argv)
if (latest)
{
reload_servers(latest->name, daemon);
check_servers(daemon);
static int warned = 0;
if (reload_servers(latest->name, daemon))
{
syslog(LOG_INFO, _("reading %s"), latest->name);
latest->mtime = last_change;
warned = 0;
check_servers(daemon);
}
else if (!warned)
{
syslog(LOG_WARNING, _("no servers found in %s, will retry"), latest->name);
warned = 1;
}
}
}
}
@@ -529,16 +542,11 @@ int main (int argc, char **argv)
/* Knock all our children on the head. */
for (i = 0; i < MAX_PROCS; i++)
if (daemon->tcp_pids[i] != 0)
kill(daemon->tcp_pids[i], SIGQUIT);
kill(daemon->tcp_pids[i], SIGALRM);
if (daemon->dhcp)
{
if (daemon->script_pid != 0)
kill(daemon->script_pid, SIGQUIT);
/* close this carefully */
fclose(daemon->lease_stream);
}
fclose(daemon->lease_stream);
exit(0);
}