> -----Original Message-----
> From: Nix [mailto:[EMAIL PROTECTED]
> Sent: Sunday, August 31, 2008 10:54 PM
> To: Giampaolo Tomassoni
> Cc: 'Giampaolo Tomassoni'; 'Marc Perkel'; users@spamassassin.apache.org
> Subject: Re: Handy script for generating /etc/resolv.conf
> 
> On 31 Aug 2008, Giampaolo Tomassoni outgrape:
> 
> > Uff!
> >
> > Stock glibc v.2.6.1, source file resolv/res_libc.c, line#167:
> >
> >     if (stat (_PATH_RESCONF, &statbuf) == 0 && last_mtime !=
> > statbuf.st_mtime) {
> >
> > _PATH_RESCONF is /etc/resolv.conf; last_mtime is the last modify time
> (the
> > previous modify time) of the /etc/resolv.conf file.
> 
> Er, um, resolv/res_libc.c in glibc 2.6.1 (and the very latest 2.8: the
> file is unchanged) is only 152 lines long. There is no reference to
> st_mtime anywhere under resolv/.
> 
> Are you sure that's stock?

Darn gentoo!

I forgot the "ebuild unpack" applies paches. Sorry, my fail.


--- libc/resolv/res_libc.c
+++ libc/resolv/res_libc.c
@@ -22,6 +22,7 @@
 #include <arpa/nameser.h>
 #include <resolv.h>
 #include <bits/libc-lock.h>
+#include <sys/stat.h>


 /* The following bit is copied from res_data.c (where it is #ifdef'ed
@@ -101,6 +102,20 @@
 __res_maybe_init (res_state resp, int preinit)
 {
        if (resp->options & RES_INIT) {
+               static time_t last_mtime, last_check;
+               time_t now;
+               struct stat statbuf;
+
+               time (&now);
+               if (now != last_check) {
+                       last_check = now;
+                       if (stat (_PATH_RESCONF, &statbuf) == 0 &&
last_mtime != statbuf.st_mtime) {
+                               last_mtime = statbuf.st_mtime;
+                               atomicinclock (lock);
+                               atomicinc (__res_initstamp);
+                               atomicincunlock (lock);
+                       }
+               }
                if (__res_initstamp != resp->_u._ext.initstamp) {
                        if (resp->nscount > 0) {
                                __res_nclose (resp);


Ok, you're right: in stock 2.7 this code is missing.


> > I don't know which glibc version you have, but trust me this code had
> been
> > there by long time.
> 
> Not in my universe :)

Well, in mine (not stock, you're right: gentoo & suse) it is. I believe it
is in many others, anyway: it doesn't make sense to me to restart
applications to commit changes in the resolv.conf file.


> > I you have a "twisted" version of glibc, please share: it is free
> software
> > and you have to publish any change to it... :)
> 
> May I second that motion? Are you *sure* yours doesn't have any distro
> patches
> applied? (Mine is straight from upstream CVS.)
> 
> This is something I can understand a distro vendor patching, and also
> something I can see Ulrich rejecting, because banging stat()s on that
> file with every name lookup seems expensive. (Doing it every minute or
> so would be acceptable to me, but IIRC Ulrich turned that down as
> well...)

SuSE & Gentoo do that at most once per second (see? now != last_check).

If you're issuing tons of requests per second, it isn't that bad anyway.

Giampaolo


> --
> `Not even vi uses vi key bindings for its command line.' --- PdS

Reply via email to