On Tue, Oct 13, 2009 at 06:11:48AM -0700, Cuero Bugot wrote:
>Hi all,
>
>We actually found the problem with gethostbyname on uClibc.
>When we change the network interface, the /etc/resolv.conf is also and 
>apparently the uClibc resolve code is not reloading the nameserver 
>configuration files.
>To fixe it we did a very simple patch (attached)  (against version uClibc 
>0.9.29).

We moved to git. See http://git.uclibc.org/uClibc
>
>The idea is that if a ns lookup fails then the nameserver file is reloaded. I 
>believe that the overhead of reloading the nameservers in case of ns lookup 
>failure is really small.

I'm not sure i understand what you say? Your scenario sounds (to me,
correct me if i'm wrong) like:
If resolv.conf changes then reload resolv.conf ¹)

>The patch is a few line long in libc/inet/resolv.c file.
>
>I have seen that in head version of resolv.c has been refactored a little 
>(which is a good thing), but this prb has not been taken care of. Instead 
>there is a new thing (which I believe is actually not very usefull): the 
>nameserver file is reloaded every 256 seconds.

That's not too helpful either, yes. ¹)
>
>The reload on failure patch could be applied on head version.

As mentioned above, svn isn't used anymore.
>
>Is anybody interested ? How can we go further ?

Not terribly interrested (the resolver could need a complete rewrite
against the SUSv4 requirements), but..

Denys, apparently you added that rereading, got a better idea than
the +60b below?

¹) attached
diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c
index 6611466..552d8b5 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 <arpa/nameser.h>
 #include <sys/utsname.h>
 #include <sys/un.h>
+#include <sys/stat.h>
 #include <bits/uClibc_mutex.h>
 
 /* poll() is not supported in kernel <= 2.0, therefore if __NR_poll is
@@ -948,19 +949,18 @@ 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;
-
        char szBuffer[MAXLEN_searchdomain];
        FILE *fp;
        int i;
        sockaddr46_t sa;
+       static time_t resolv_conf_mtime;
 
        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 ((difftime(resolv_conf_mtime, sb.st_mtime)) < 0) {
+                       resolv_conf_mtime = sb.st_mtime;
                        __close_nameservers(); /* force config reread */
                }
        }
@@ -969,6 +969,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 +977,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) {
_______________________________________________
uClibc mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/uclibc

Reply via email to