This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] resolv/resolv.h: allow alternative resolv.conf files

> _PATH_RESCONF really has to be a string literal, and you can't use a GNU
> C extension in such a way in an installed header file.
> The environment variable would have to be ignored in AT_SECURE mode, so
> you have to use __libc_secure_getenv or put it into unsecvars.h.

Here is a different implementation:
* it does not use any gcc extension
* use __libc_secure_getenv instead of getenv
* do not change installed header files.

Thank you.	

2017-08-17 Renzo Davoli <>

diff --git a/resolv/res_init.c b/resolv/res_init.c
index fa46ce7813..bca60568ad 100644
--- a/resolv/res_init.c
+++ b/resolv/res_init.c
@@ -545,7 +545,7 @@ __resolv_conf_load (struct __res_state *preinit)
   /* Ensure that /etc/hosts.conf has been loaded (once).  */
   _res_hconf_init ();
-  FILE *fp = fopen (_PATH_RESCONF, "rce");
+  FILE *fp = fopen (__resolv_path_resconf(), "rce");
   if (fp == NULL)
     switch (errno)
diff --git a/resolv/resolv-internal.h b/resolv/resolv-internal.h
index 32dc44777e..aa52497550 100644
--- a/resolv/resolv-internal.h
+++ b/resolv/resolv-internal.h
@@ -97,4 +97,8 @@ int __res_nopt (struct resolv_context *, int n0,
 int __inet_pton_length (int af, const char *src, size_t srclen, void *);
 libc_hidden_proto (__inet_pton_length)
+/* Return the current fileto use as resolv.conf 
+	 __PATH_RESCONF o the value of the env var PATH_RESCONF if it exists*/
+const char *__resolv_path_resconf(void);
 #endif  /* _RESOLV_INTERNAL_H */
diff --git a/resolv/resolv_conf.c b/resolv/resolv_conf.c
index f391d30c27..9896e64cdc 100644
--- a/resolv/resolv_conf.c
+++ b/resolv/resolv_conf.c
@@ -119,11 +119,19 @@ conf_decrement (struct resolv_conf *conf)
     free (conf);
+const char *__resolv_path_resconf(void) {
+	char *path_resconf = __libc_secure_getenv("PATH_RESCONF");
+	if (path_resconf)
+		return path_resconf;
+	else
+		return _PATH_RESCONF;
 struct resolv_conf *
 __resolv_conf_get_current (void)
   struct stat64 st;
-  if (stat64 (_PATH_RESCONF, &st) != 0)
+  if (stat64 (__resolv_path_resconf(), &st) != 0)
     switch (errno)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]