From fea942bf0a3daf5e1eebc6a7a6f252abbba65009 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 13 Oct 2009 22:34:15 +0200 Subject: libc/inet/resolv.c: reread resolv.conf if its mtime was changed Signed-off-by: Bernhard Reutner-Fischer Signed-off-by: Denys Vlasenko --- libc/inet/resolv.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c index 66114668c..ee06b44be 100644 --- a/libc/inet/resolv.c +++ b/libc/inet/resolv.c @@ -312,6 +312,7 @@ Domain name in a message can be represented as either: #include #include #include +#include #include /* poll() is not supported in kernel <= 2.0, therefore if __NR_poll is @@ -948,7 +949,7 @@ static char *skip_and_NUL_space(char *p) /* Must be called under __resolv_lock. */ void attribute_hidden __open_nameservers(void) { - static uint8_t last_time; + static uint32_t resolv_conf_mtime; char szBuffer[MAXLEN_searchdomain]; FILE *fp; @@ -956,11 +957,11 @@ void attribute_hidden __open_nameservers(void) sockaddr46_t sa; if (!__res_sync) { - /* Provide for periodic reread of /etc/resolv.conf */ - /* cur_time "ticks" every 256 seconds */ - uint8_t cur_time = ((unsigned)time(NULL)) >> 8; - if (last_time != cur_time) { - last_time = cur_time; + /* Reread /etc/resolv.conf if it was modified. */ + struct stat sb; + stat("/etc/resolv.conf", &sb); + if (resolv_conf_mtime != (uint32_t)sb.st_mtime) { + resolv_conf_mtime = sb.st_mtime; __close_nameservers(); /* force config reread */ } } @@ -969,6 +970,7 @@ void attribute_hidden __open_nameservers(void) goto sync; fp = fopen("/etc/resolv.conf", "r"); +#ifdef FALLBACK_TO_CONFIG_RESOLVCONF if (!fp) { /* If we do not have a pre-populated /etc/resolv.conf then try to use the one from /etc/config which exists on numerous @@ -976,6 +978,7 @@ void attribute_hidden __open_nameservers(void) may be the only /etc dir that was mounted rw. */ fp = fopen("/etc/config/resolv.conf", "r"); } +#endif if (fp) { while (fgets(szBuffer, sizeof(szBuffer), fp) != NULL) { -- cgit v1.2.3