vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| the first time the resolver is used, it calls res_init(), which reads resolv.conf once and pretty much never again. this works until your nameserver's ip changes (dhcp, different network, rearrange things, ...). any app that was running before stops working until you restart it. some apps may solve this by running res_init by hand, but of course, some don't. i also consider it a bit of a hack for a program to need to know to do such things. diff below stats resolv.conf if the last check was more than 30 seconds ago. it makes mozilla much happier when i switch networks. by happy, i mean functional. Index: include/resolv.h ================================================== ================= RCS file: /cvs/src/include/resolv.h,v retrieving revision 1.15 diff -u -r1.15 resolv.h --- include/resolv.h 2004/01/22 21:48:02 1.15 +++ include/resolv.h 2005/03/26 08:37:44 @@ -134,7 +134,7 @@ struct __res_state { int retrans; /* retransmission time interval */ int retry; /* number of times to retransmit */ - unsigned long options; /* option flags - see below. */ + unsigned int options; /* option flags - see below. */ int nscount; /* number of name servers */ struct sockaddr_in nsaddr_list[MAXNS]; /* address of name server */ @@ -142,7 +142,7 @@ unsigned short id; /* current message id */ char *dnsrch[MAXDNSRCH+1]; /* components of domain to search */ char defdname[256]; /* default domain (deprecated) */ - unsigned long pfcode; /* RES_PRF_ flags - see below. */ + unsigned int pfcode; /* RES_PRF_ flags - see below. */ unsigned ndots:4; /* threshold for initial abs. query */ unsigned nsort:4; /* number of elements in sort_list[] */ char unused[3]; @@ -151,7 +151,13 @@ u_int32_t mask; } sort_list[MAXRESOLVSORT]; char lookups[MAXDNSLUS]; - char pad[68]; /* on an i386 this means 512b total */ + struct timespec restimespec; + time_t reschktime; +#ifdef __LP64 + char pad[52]; /* should be 512b total */ +#else + char pad[56]; /* should be 512b total */ +#endif }; #if 1 /* INET6 */ Index: lib/libc/net/getaddrinfo.c ================================================== ================= RCS file: /cvs/src/lib/libc/net/getaddrinfo.c,v retrieving revision 1.50 diff -u -r1.50 getaddrinfo.c --- lib/libc/net/getaddrinfo.c 2004/06/07 21:11:23 1.50 +++ lib/libc/net/getaddrinfo.c 2005/03/26 08:37:45 @@ -522,7 +522,7 @@ return 0; } - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) + if (_resp->reschktime < time(NULL) && res_init() == -1) strlcpy(lookups, "f", sizeof lookups); else { bcopy(_resp->lookups, lookups, sizeof lookups); @@ -1571,7 +1571,7 @@ rcode = NOERROR; ancount = 0; - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { + if (_resp->reschktime < time(NULL) && res_init() == -1) { h_errno = NETDB_INTERNAL; free(buf); return (-1); @@ -1679,7 +1679,7 @@ int trailing_dot, ret, saved_herrno; int got_nodata = 0, got_servfail = 0, tried_as_is = 0; - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { + if (_resp->reschktime < time(NULL) && res_init() == -1) { h_errno = NETDB_INTERNAL; return (-1); } @@ -1817,7 +1817,7 @@ const char *longname = nbuf; size_t n, d; - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { + if (_resp->reschktime < time(NULL) && res_init() == -1) { h_errno = NETDB_INTERNAL; return (-1); } Index: lib/libc/net/gethostnamadr.c ================================================== ================= RCS file: /cvs/src/lib/libc/net/gethostnamadr.c,v retrieving revision 1.60 diff -u -r1.60 gethostnamadr.c --- lib/libc/net/gethostnamadr.c 2004/07/29 03:09:40 1.60 +++ lib/libc/net/gethostnamadr.c 2005/03/26 08:37:46 @@ -479,7 +479,7 @@ struct hostent *hp; extern struct hostent *_gethtbyname2(const char *, int); - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) + if (_resp->reschktime < time(NULL) && res_init() == -1) hp = _gethtbyname2(name, AF_INET); else if (_resp->options & RES_USE_INET6) { @@ -505,7 +505,7 @@ extern struct hostent *_gethtbyname2(const char *, int); extern struct hostent *_yp_gethtbyname(const char *); - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) + if (_resp->reschktime < time(NULL) && res_init() == -1) return (_gethtbyname2(name, af)); switch (af) { @@ -653,7 +653,7 @@ extern struct hostent *_gethtbyaddr(const char *, int, int); extern struct hostent *_yp_gethtbyaddr(const char *); - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { + if (_resp->reschktime < time(NULL) && res_init() == -1) { res = _gethtbyaddr(addr, len, af); return (res); } Index: lib/libc/net/getnetnamadr.c ================================================== ================= RCS file: /cvs/src/lib/libc/net/getnetnamadr.c,v retrieving revision 1.23 diff -u -r1.23 getnetnamadr.c --- lib/libc/net/getnetnamadr.c 2003/06/03 21:09:00 1.23 +++ lib/libc/net/getnetnamadr.c 2005/03/26 08:37:46 @@ -264,7 +264,7 @@ char lookups[MAXDNSLUS]; int i; - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) + if (_resp->reschktime < time(NULL) && res_init() == -1) return(_getnetbyaddr(net, net_type)); bcopy(_resp->lookups, lookups, sizeof lookups); @@ -353,7 +353,7 @@ char lookups[MAXDNSLUS]; int i; - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) + if (_resp->reschktime < time(NULL) && res_init() == -1) return (_getnetbyname(net)); bcopy(_resp->lookups, lookups, sizeof lookups); Index: lib/libc/net/getrrsetbyname.c ================================================== ================= RCS file: /cvs/src/lib/libc/net/getrrsetbyname.c,v retrieving revision 1.8 diff -u -r1.8 getrrsetbyname.c --- lib/libc/net/getrrsetbyname.c 2004/07/18 19:07:38 1.8 +++ lib/libc/net/getrrsetbyname.c 2005/03/26 08:37:46 @@ -126,7 +126,7 @@ } /* initialize resolver */ - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { + if (_resp->reschktime < time(NULL) && res_init() == -1) { result = ERRSET_FAIL; goto fail; } Index: lib/libc/net/res_debug.c ================================================== ================= RCS file: /cvs/src/lib/libc/net/res_debug.c,v retrieving revision 1.17 diff -u -r1.17 res_debug.c --- lib/libc/net/res_debug.c 2003/06/02 20:18:36 1.17 +++ lib/libc/net/res_debug.c 2005/03/26 08:37:48 @@ -275,7 +275,7 @@ register const HEADER *hp; register int n; - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) + if (_resp->reschktime < time(NULL) && res_init() == -1) return; #define TruncTest(x) if (x > endMark) goto trunc @@ -488,7 +488,7 @@ char rrname[MAXDNAME]; /* The fqdn of this RR */ char base64_key[MAX_KEY_BASE64]; - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { + if (_resp->reschktime < time(NULL) && res_init() == -1) { h_errno = NETDB_INTERNAL; return (NULL); } Index: lib/libc/net/res_init.c ================================================== ================= RCS file: /cvs/src/lib/libc/net/res_init.c,v retrieving revision 1.30 diff -u -r1.30 res_init.c --- lib/libc/net/res_init.c 2004/06/07 21:11:23 1.30 +++ lib/libc/net/res_init.c 2005/03/26 08:37:48 @@ -68,6 +68,7 @@ #include <sys/param.h> #include <sys/socket.h> #include <sys/time.h> +#include <sys/stat.h> #include <netinet/in.h> #include <arpa/inet.h> #include <arpa/nameser.h> @@ -131,6 +132,8 @@ struct __res_state_ext _res_ext; #endif /* INET6 */ +int __res_chktime = 30; + /* * Set up default settings. If the configuration file exist, the values * there will have precedence. Otherwise, the server address is set to @@ -155,6 +158,7 @@ int res_init() { + struct stat sb; struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); #ifdef INET6 struct __res_state_ext *_res_extp = _THREAD_PRIVATE(_res_ext, _res_ext, @@ -175,6 +179,14 @@ #ifndef RFC1535 int dots; #endif + + if (!stat(_PATH_RESCONF, &sb)) { + _resp->reschktime = time(NULL) + __res_chktime; + if (timespeccmp(&sb.st_mtimespec, &_resp->restimespec, ==)) + return; + else + _resp->restimespec = sb.st_mtimespec; + } /* * These three fields used to be statically initialized. This made Index: lib/libc/net/res_mkquery.c ================================================== ================= RCS file: /cvs/src/lib/libc/net/res_mkquery.c,v retrieving revision 1.14 diff -u -r1.14 res_mkquery.c --- lib/libc/net/res_mkquery.c 2003/06/02 20:18:36 1.14 +++ lib/libc/net/res_mkquery.c 2005/03/26 08:37:48 @@ -94,7 +94,7 @@ register int n; u_char *dnptrs[20], **dpp, **lastdnptr; - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { + if (_resp->reschktime < time(NULL) && res_init() == -1) { h_errno = NETDB_INTERNAL; return (-1); } Index: lib/libc/net/res_query.c ================================================== ================= RCS file: /cvs/src/lib/libc/net/res_query.c,v retrieving revision 1.21 diff -u -r1.21 res_query.c --- lib/libc/net/res_query.c 2003/06/02 20:18:36 1.21 +++ lib/libc/net/res_query.c 2005/03/26 08:37:49 @@ -111,7 +111,7 @@ hp->rcode = NOERROR; /* default */ - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { + if (_resp->reschktime < time(NULL) && res_init() == -1) { h_errno = NETDB_INTERNAL; return (-1); } @@ -193,7 +193,7 @@ int trailing_dot, ret, saved_herrno; int got_nodata = 0, got_servfail = 0, tried_as_is = 0; - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { + if (_resp->reschktime < time(NULL) && res_init() == -1) { h_errno = NETDB_INTERNAL; return (-1); } @@ -331,7 +331,7 @@ const char *longname = nbuf; int n; - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { + if (_resp->reschktime < time(NULL) && res_init() == -1) { h_errno = NETDB_INTERNAL; return (-1); } Index: lib/libc/net/res_send.c ================================================== ================= RCS file: /cvs/src/lib/libc/net/res_send.c,v retrieving revision 1.16 diff -u -r1.16 res_send.c --- lib/libc/net/res_send.c 2004/11/17 01:42:26 1.16 +++ lib/libc/net/res_send.c 2005/03/26 08:37:49 @@ -361,7 +361,7 @@ register int n; u_int badns; /* XXX NSMAX can't exceed #/bits in this var */ - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { + if (_resp->reschktime < time(NULL) && res_init() == -1) { /* errno should have been set by res_init() in this case. */ return (-1); } Index: lib/libc/net/sethostent.c ================================================== ================= RCS file: /cvs/src/lib/libc/net/sethostent.c,v retrieving revision 1.6 diff -u -r1.6 sethostent.c --- lib/libc/net/sethostent.c 2003/06/02 20:18:36 1.6 +++ lib/libc/net/sethostent.c 2005/03/26 08:37:49 @@ -45,7 +45,7 @@ { struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) + if (_resp->reschktime < time(NULL) && res_init() == -1) return; if (stayopen) _resp->options |= RES_STAYOPEN | RES_USEVC; -- we want to stop reading magazines stop watching tv stop caring about hollywood but we're addicted to the things we hate |