gethostbyname

Bernhard Reutner-Fischer rep.dot.nop at gmail.com
Wed Oct 14 06:31:23 UTC 2009


Huh?
Why on earth would we care about a missing resolv.conf there?

On Oct 14, 2009 2:21 AM, "Timothy Holdener" <tgh1138 at acm.org> wrote:

On Tue, Oct 13, 2009 at 09:02:10PM +0200, Denys Vlasenko wrote:

>Perhaps I thought time() is cheaper than stat(), but

that's what i thought, yes :)

>this patch will make us see new /etc/resolv.conf
>at once -> better user experience. I like it.
>
>
>+       static time_t resolv_conf_mtime;
>...
>+               struct stat sb;
>+               stat("/etc/resolv.conf", &sb);
>+               if ((difftime(resolv_conf_mtime, sb.st_mtime)) < 0) {
>

I came up with the same solution to this problem a month or two ago.
(i.e. using 'stat' to determine if resolv.conf has changed.)
Since we are using a 3-year-old version of uclibc, I never got around
to making a patch compatible with the current code and submitting it.

Bernhard's solution has one problem in that the call to stat will
fail if /etc/resolv.conf does not exist. In that case, the value
of sb.st_mtime is indeterminate.  Here is a patch that should account
for that case:
---------------------------------------
--- a/libc/inet/resolv.c    2009-10-13 16:47:31.000000000 -0700
+++ b/libc/inet/resolv.c    2009-10-13 16:50:34.000000000 -0700
@@ -959,8 +959,13 @@
       if (!__res_sync) {
               /* 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) {
+               if (stat("/etc/resolv.conf", &sb) < 0) {
+#ifdef FALLBACK_TO_CONFIG_RESOLVCONF
+                       if (stat("/etc/config/resolv.conf", &sb) < 0)
+#endif
+                               sb.st_mtime = 0;
+               }
+               if ((sb.st_mtime != 0) && (resolv_conf_mtime !=
(uint32_t)sb.st_mtime)) {
                       resolv_conf_mtime = sb.st_mtime;
                       __close_nameservers(); /* force config reread */
               }
---------------------------------------

--
_______________________________________________
uClibc mailing list
uClibc at uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc


More information about the uClibc mailing list