From e6b4e2de6dd91efdcac80b79149c596de8a26b70 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Tue, 27 Jun 2017 09:26:46 +0200 Subject: resolv: Call _res_hconf_init from __res_vinit Many callers of __res_maybe_init also call _res_hconf_init. Additional calls to the latter do not hurt because the function does its work only once. (/etc/hosts.conf is not reloaded or even checked for changes.) This means that we can simplify the code by calling _res_hconf_init directly from __res_vinit. --- ChangeLog | 19 +++++++++++++++++++ inet/gethstbyad_r.c | 3 +-- inet/gethstbynm2_r.c | 4 ++-- inet/gethstbynm_r.c | 4 ++-- nscd/aicache.c | 2 -- nscd/gethstbyad_r.c | 1 - nscd/gethstbynm3_r.c | 2 +- nss/getXXbyYY_r.c | 6 ------ resolv/res_hconf.h | 2 +- resolv/res_init.c | 4 ++++ sysdeps/posix/getaddrinfo.c | 2 -- 11 files changed, 30 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index aec70b6932..279059b299 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2017-06-27 Florian Weimer + + Call _res_hconf_init from __res_vinit. + * inet/gethstbyad_r.c (NEED__RES_HCONF): Remove. + * inet/gethstbynm2_r.c (NEED__RES_HCONF): Likewise. + (NEED__RES): Define. + * inet/gethstbynm_r.c (NEED__RES_HCONF): Remove. + (NEED__RES): Define. + * nscd/aicache.c (addhstaiX): Remove call to _res_hconf_init. + * nscd/gethstbyad_r.c (NEED__RES_HCONF): Remove. + * nscd/gethstbynm3_r.c (NEED__RES_HCONF): Likewise. + (NEED__RES): Define. + * nss/getXXbyYY_r.c (REENTRANT_NAME): Remove call to + _res_hconf_init. + * resolv/res_hconf.h (_res_hconf_init): Declare as hidden. + * resolv/res_init.c (__res_vinit): Call _res_hconf_init. + * sysdeps/posix/getaddrinfo.c (gaih_inet): Remove call to + _res_hconf_init. + 2017-06-26 Joseph Myers * sysdeps/ia64/Implies: Add ieee754/float128. diff --git a/inet/gethstbyad_r.c b/inet/gethstbyad_r.c index 88f428c1db..6b5c131050 100644 --- a/inet/gethstbyad_r.c +++ b/inet/gethstbyad_r.c @@ -18,7 +18,7 @@ #include #include - +#include #define LOOKUP_TYPE struct hostent #define FUNCTION_NAME gethostbyaddr @@ -27,7 +27,6 @@ #define ADD_VARIABLES addr, len, type #define NEED_H_ERRNO 1 #define NEED__RES 1 -#define NEED__RES_HCONF 1 /* If the addr parameter is the IPv6 unspecified address no query must be performed. */ #define PREPROCESS \ diff --git a/inet/gethstbynm2_r.c b/inet/gethstbynm2_r.c index 5704797990..580ba6d1cf 100644 --- a/inet/gethstbynm2_r.c +++ b/inet/gethstbynm2_r.c @@ -22,7 +22,7 @@ #include #include #include - +#include #define LOOKUP_TYPE struct hostent #define FUNCTION_NAME gethostbyname2 @@ -30,7 +30,7 @@ #define ADD_PARAMS const char *name, int af #define ADD_VARIABLES name, af #define NEED_H_ERRNO 1 -#define NEED__RES_HCONF 1 +#define NEED__RES 1 #define POSTPROCESS \ if (status == NSS_STATUS_SUCCESS) \ _res_hconf_reorder_addrs (resbuf); diff --git a/inet/gethstbynm_r.c b/inet/gethstbynm_r.c index 3758a9dde8..8f464b5ff1 100644 --- a/inet/gethstbynm_r.c +++ b/inet/gethstbynm_r.c @@ -22,7 +22,7 @@ #include #include #include - +#include #define LOOKUP_TYPE struct hostent #define FUNCTION_NAME gethostbyname @@ -30,7 +30,7 @@ #define ADD_PARAMS const char *name #define ADD_VARIABLES name #define NEED_H_ERRNO 1 -#define NEED__RES_HCONF 1 +#define NEED__RES 1 #define POSTPROCESS \ if (status == NSS_STATUS_SUCCESS) \ _res_hconf_reorder_addrs (resbuf); diff --git a/nscd/aicache.c b/nscd/aicache.c index 7bf4131979..f1f9284f6d 100644 --- a/nscd/aicache.c +++ b/nscd/aicache.c @@ -26,7 +26,6 @@ #include #include #include -#include #include "dbg_log.h" #include "nscd.h" @@ -102,7 +101,6 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req, nip = hosts_database; /* Initialize configurations. */ - _res_hconf_init (); if (__res_maybe_init (&_res, 0) == -1) no_more = 1; diff --git a/nscd/gethstbyad_r.c b/nscd/gethstbyad_r.c index b17f0d2b51..842ced2ec6 100644 --- a/nscd/gethstbyad_r.c +++ b/nscd/gethstbyad_r.c @@ -28,7 +28,6 @@ #define EXTRA_VARIABLES , ttlp #define NEED_H_ERRNO 1 #define NEED__RES 1 -#define NEED__RES_HCONF 1 /* We are nscd, so we don't want to be talking to ourselves. */ #undef USE_NSCD diff --git a/nscd/gethstbynm3_r.c b/nscd/gethstbynm3_r.c index 41bb26845d..2ab75e469e 100644 --- a/nscd/gethstbynm3_r.c +++ b/nscd/gethstbynm3_r.c @@ -32,7 +32,7 @@ #define ADD_VARIABLES name, af #define EXTRA_VARIABLES , ttlp, canonp #define NEED_H_ERRNO 1 -#define NEED__RES_HCONF 1 +#define NEED__RES 1 #define HANDLE_DIGITS_DOTS 1 #define HAVE_LOOKUP_BUFFER 1 diff --git a/nss/getXXbyYY_r.c b/nss/getXXbyYY_r.c index 5962475737..7cab825cf0 100644 --- a/nss/getXXbyYY_r.c +++ b/nss/getXXbyYY_r.c @@ -25,9 +25,6 @@ #ifdef USE_NSCD # include #endif -#ifdef NEED__RES_HCONF -# include -#endif #ifdef NEED__RES # include #endif @@ -273,9 +270,6 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer, return errno; } #endif /* need _res */ -#ifdef NEED__RES_HCONF - _res_hconf_init (); -#endif /* need _res_hconf */ void *tmp_ptr = fct.l; #ifdef PTR_MANGLE diff --git a/resolv/res_hconf.h b/resolv/res_hconf.h index 6eaf4039f3..209f76a0d6 100644 --- a/resolv/res_hconf.h +++ b/resolv/res_hconf.h @@ -46,7 +46,7 @@ struct hconf }; extern struct hconf _res_hconf; -extern void _res_hconf_init (void); +extern void _res_hconf_init (void) attribute_hidden; extern void _res_hconf_trim_domain (char *domain); extern void _res_hconf_trim_domains (struct hostent *hp); extern void _res_hconf_reorder_addrs (struct hostent *hp); diff --git a/resolv/res_init.c b/resolv/res_init.c index 9aa907ee19..821f06061b 100644 --- a/resolv/res_init.c +++ b/resolv/res_init.c @@ -85,6 +85,7 @@ #include #include #include +#include #include #include #include @@ -430,6 +431,9 @@ res_vinit_1 (res_state statp, bool preinit, FILE *fp, char **buffer) int __res_vinit (res_state statp, int preinit) { + /* Ensure that /etc/hosts.conf has been loaded (once). */ + _res_hconf_init (); + FILE *fp = fopen (_PATH_RESCONF, "rce"); if (fp == NULL) switch (errno) diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c index 91e0a76c5c..4fb1eaef79 100644 --- a/sysdeps/posix/getaddrinfo.c +++ b/sysdeps/posix/getaddrinfo.c @@ -80,7 +80,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include #include #include @@ -767,7 +766,6 @@ gaih_inet (const char *name, const struct gaih_service *service, nip = __nss_hosts_database; /* Initialize configurations. */ - _res_hconf_init (); if (__res_maybe_init (&_res, 0) == -1) no_more = 1; -- cgit 1.4.1