gethostbyname problem

Denys Vlasenko vda.linux at googlemail.com
Tue Oct 13 19:02:10 UTC 2009


On Tuesday 13 October 2009 19:11, Bernhard Reutner-Fischer wrote:
> 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?

Perhaps I thought time() is cheaper than stat(), but
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) {

To use difftime here looks like overkill:

double difftime(time_t time1, time_t time0);

You don't need the difference. You only want to know whether it
has changed, right?



I propose using:

        static unsigned resolv_conf_mtime;
...
        if (resolv_conf_mtime != (unsigned)sb.st_mtime) < 0) {

I use "unsigned" in order to minimize statics - time_t is a long, and
there is no need to use 8 bytes on amd64 etc where 4 is quite enough.

We can explicitly use uint32_t there if you are concerned we'll
ever get arches with sizeof(int) > 4.
(Rob doesn't think we will. 640k should be enough for anyone).

Apart from that, looks ok.

--
vda


More information about the uClibc mailing list