From 01f36609ba1631751e492784d95b0e6b0706cf45 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 4 Nov 2009 17:17:53 +0100 Subject: abrtd: call res_init() if /etc/resolv.conf or friends were changed Signed-off-by: Denys Vlasenko --- src/Daemon/Daemon.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/Daemon/Daemon.cpp') diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index af4f9dc..175efe9 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -19,6 +19,7 @@ #include #include +#include /* res_init */ #include #include #include @@ -594,6 +595,8 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin static void run_main_loop(GMainLoop* loop) { GMainContext *context = g_main_loop_get_context(loop); + time_t old_time = 0; + time_t dns_conf_hash = 0; while (!s_exiting) { @@ -618,6 +621,33 @@ static void run_main_loop(GMainLoop* loop) if (s_timeout) alarm(0); + /* res_init() makes glibc reread /etc/resolv.conf. + * I'd think libc should be clever enough to do it itself + * at every name resolution attempt, but no... + * We need to guess ourself whether we want to do it. + */ + time_t now = time(NULL) >> 2; + if (old_time != now) /* check once in 4 seconds */ + { + old_time = now; + + time_t hash = 0; + struct stat sb; + if (stat("/etc/resolv.conf", &sb) == 0) + hash = sb.st_mtime; + if (stat("/etc/host.conf", &sb) == 0) + hash += sb.st_mtime; + if (stat("/etc/hosts", &sb) == 0) + hash += sb.st_mtime; + if (stat("/etc/nsswitch.conf", &sb) == 0) + hash += sb.st_mtime; + if (dns_conf_hash != hash) + { + dns_conf_hash = hash; + res_init(); + } + } + some_ready = g_main_context_check(context, max_priority, fds, nfds); if (some_ready) g_main_context_dispatch(context); -- cgit