summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/res_init.c
diff options
context:
space:
mode:
authortedu <>2005-03-30 02:58:28 +0000
committertedu <>2005-03-30 02:58:28 +0000
commit3b040f7dfaf37c407ea6ede1c8c2092e6bf903fd (patch)
treea8ff98cee0b13b3b8eeae1624d717e734dc22bb7 /src/lib/libc/net/res_init.c
parentcc22824e6cee4353df96b7aeec5d080789306136 (diff)
downloadopenbsd-3b040f7dfaf37c407ea6ede1c8c2092e6bf903fd.tar.gz
openbsd-3b040f7dfaf37c407ea6ede1c8c2092e6bf903fd.tar.bz2
openbsd-3b040f7dfaf37c407ea6ede1c8c2092e6bf903fd.zip
make the resolver stat resolv.conf and update if it changes.
useful feedback and ok deraadt@
Diffstat (limited to 'src/lib/libc/net/res_init.c')
-rw-r--r--src/lib/libc/net/res_init.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/src/lib/libc/net/res_init.c b/src/lib/libc/net/res_init.c
index f4a8d31cb1..110542a404 100644
--- a/src/lib/libc/net/res_init.c
+++ b/src/lib/libc/net/res_init.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: res_init.c,v 1.31 2005/03/25 13:24:12 otto Exp $ */ 1/* $OpenBSD: res_init.c,v 1.32 2005/03/30 02:58:28 tedu Exp $ */
2 2
3/* 3/*
4 * ++Copyright++ 1985, 1989, 1993 4 * ++Copyright++ 1985, 1989, 1993
@@ -60,7 +60,7 @@
60static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; 60static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93";
61static char rcsid[] = "$From: res_init.c,v 8.7 1996/09/28 06:51:07 vixie Exp $"; 61static char rcsid[] = "$From: res_init.c,v 8.7 1996/09/28 06:51:07 vixie Exp $";
62#else 62#else
63static char rcsid[] = "$OpenBSD: res_init.c,v 1.31 2005/03/25 13:24:12 otto Exp $"; 63static char rcsid[] = "$OpenBSD: res_init.c,v 1.32 2005/03/30 02:58:28 tedu Exp $";
64#endif 64#endif
65#endif /* LIBC_SCCS and not lint */ 65#endif /* LIBC_SCCS and not lint */
66 66
@@ -68,6 +68,7 @@ static char rcsid[] = "$OpenBSD: res_init.c,v 1.31 2005/03/25 13:24:12 otto Exp
68#include <sys/param.h> 68#include <sys/param.h>
69#include <sys/socket.h> 69#include <sys/socket.h>
70#include <sys/time.h> 70#include <sys/time.h>
71#include <sys/stat.h>
71#include <netinet/in.h> 72#include <netinet/in.h>
72#include <arpa/inet.h> 73#include <arpa/inet.h>
73#include <arpa/nameser.h> 74#include <arpa/nameser.h>
@@ -131,6 +132,8 @@ void *__THREAD_NAME(_res_ext);
131struct __res_state_ext _res_ext; 132struct __res_state_ext _res_ext;
132#endif /* INET6 */ 133#endif /* INET6 */
133 134
135int __res_chktime = 30;
136
134/* 137/*
135 * Set up default settings. If the configuration file exist, the values 138 * Set up default settings. If the configuration file exist, the values
136 * there will have precedence. Otherwise, the server address is set to 139 * there will have precedence. Otherwise, the server address is set to
@@ -155,6 +158,14 @@ struct __res_state_ext _res_ext;
155int 158int
156res_init(void) 159res_init(void)
157{ 160{
161
162 return (_res_init(1));
163}
164
165int
166_res_init(int usercall)
167{
168 struct stat sb;
158 struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); 169 struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res);
159#ifdef INET6 170#ifdef INET6
160 struct __res_state_ext *_res_extp = _THREAD_PRIVATE(_res_ext, _res_ext, 171 struct __res_state_ext *_res_extp = _THREAD_PRIVATE(_res_ext, _res_ext,
@@ -176,6 +187,29 @@ res_init(void)
176 int dots; 187 int dots;
177#endif 188#endif
178 189
190 if (usercall == 0) {
191 if (_resp->options & RES_INIT &&
192 _resp->reschktime >= time(NULL))
193 return (0);
194 _resp->reschktime = time(NULL) + __res_chktime;
195 if (stat(_PATH_RESCONF, &sb) != -1) {
196 if (timespeccmp(&sb.st_mtimespec,
197 &_resp->restimespec, ==))
198 return (0);
199 else
200 _resp->restimespec = sb.st_mtimespec;
201 } else {
202 /*
203 * Lost the file, in chroot?
204 * Don' trash settings
205 */
206 if (timespecisset(&_resp->restimespec))
207 return (0);
208 }
209 } else
210 _resp->reschktime = time(NULL) + __res_chktime;
211
212
179 /* 213 /*
180 * These three fields used to be statically initialized. This made 214 * These three fields used to be statically initialized. This made
181 * it hard to use this code in a shared library. It is necessary, 215 * it hard to use this code in a shared library. It is necessary,