diff options
author | Florian Weimer <fweimer@redhat.com> | 2017-06-30 21:10:23 +0200 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2017-07-03 20:52:59 +0200 |
commit | 352f4ff9a268b81ef5d4b2413f582565806e4790 (patch) | |
tree | fb27056dfdeafe43c021f6127c9544c016e78019 /nss/getXXbyYY_r.c | |
parent | 4e45d83c92dbb5b8dc20654f32395108d18cf739 (diff) | |
download | glibc-352f4ff9a268b81ef5d4b2413f582565806e4790.tar.gz |
resolv: Introduce struct resolv_context [BZ #21668]
struct resolv_context objects provide a temporary resolver context
which does not change during a name lookup operation. Only when the
outmost context is created, the stub resolver configuration is
verified to be current (at present, only against previous res_init
calls). Subsequent attempts to obtain the context will reuse the
result of the initial verification operation.
struct resolv_context can also be extended in the future to store
data which needs to be deallocated during thread cancellation.
Diffstat (limited to 'nss/getXXbyYY_r.c')
-rw-r--r-- | nss/getXXbyYY_r.c | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/nss/getXXbyYY_r.c b/nss/getXXbyYY_r.c index 7cab825cf0..6c547ea1ca 100644 --- a/nss/getXXbyYY_r.c +++ b/nss/getXXbyYY_r.c @@ -26,7 +26,7 @@ # include <nscd/nscd_proto.h> #endif #ifdef NEED__RES -# include <resolv.h> +# include <resolv/resolv_context.h> #endif /*******************************************************************\ |* Here we assume several symbols to be defined: *| @@ -53,8 +53,7 @@ |* NEED_H_ERRNO - an extra parameter will be passed to point to *| |* the global `h_errno' variable. *| |* *| -|* NEED__RES - the global _res variable might be used so we *| -|* will have to initialize it if necessary *| +|* NEED__RES - obtain a struct resolv_context resolver context *| |* *| |* PREPROCESS - code run before anything else *| |* *| @@ -213,6 +212,18 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer, bool any_service = false; #endif +#ifdef NEED__RES + /* The HANDLE_DIGITS_DOTS case below already needs the resolver + configuration, so this has to happen early. */ + struct resolv_context *res_ctx = __resolv_context_get (); + if (res_ctx == NULL) + { + *h_errnop = NETDB_INTERNAL; + *result = NULL; + return errno; + } +#endif /* NEED__RES */ + #ifdef PREPROCESS PREPROCESS; #endif @@ -260,17 +271,6 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer, } else { -#ifdef NEED__RES - /* The resolver code will really be used so we have to - initialize it. */ - if (__res_maybe_init (&_res, 0) == -1) - { - *h_errnop = NETDB_INTERNAL; - *result = NULL; - return errno; - } -#endif /* need _res */ - void *tmp_ptr = fct.l; #ifdef PTR_MANGLE PTR_MANGLE (tmp_ptr); @@ -399,6 +399,12 @@ done: POSTPROCESS; #endif +#ifdef NEED__RES + /* This has to happen late because the POSTPROCESS stage above might + need the resolver context. */ + __resolv_context_put (res_ctx); +#endif /* NEED__RES */ + int res; if (status == NSS_STATUS_SUCCESS || status == NSS_STATUS_NOTFOUND) res = 0; |