summaryrefslogtreecommitdiffstats
path: root/src/Daemon/Daemon.cpp
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-11-04 17:17:53 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2009-11-04 17:17:53 +0100
commit01f36609ba1631751e492784d95b0e6b0706cf45 (patch)
treef9a2b0457cb13ff7481502171417df80ae298baa /src/Daemon/Daemon.cpp
parent7ea8edef92be0c7812699d3e9d9a20bad8227ef3 (diff)
downloadabrt-01f36609ba1631751e492784d95b0e6b0706cf45.tar.gz
abrt-01f36609ba1631751e492784d95b0e6b0706cf45.tar.xz
abrt-01f36609ba1631751e492784d95b0e6b0706cf45.zip
abrtd: call res_init() if /etc/resolv.conf or friends were changed
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'src/Daemon/Daemon.cpp')
-rw-r--r--src/Daemon/Daemon.cpp30
1 files changed, 30 insertions, 0 deletions
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 <syslog.h>
#include <pthread.h>
+#include <resolv.h> /* res_init */
#include <string>
#include <limits.h>
#include <sys/inotify.h>
@@ -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);