From: Stefan Sedich <stefan.sedich@gmail.com>
To: musl@lists.openwall.com
Cc: Stefan Sedich <stefan.sedich@gmail.com>
Subject: [PATCH] Add RES_OPTIONS support for resolv.conf options overriding
Date: Mon, 24 Apr 2017 19:21:22 -0700 [thread overview]
Message-ID: <20170425022122.27281-1-stefan.sedich@gmail.com> (raw)
Currently glibc supports using the RES_OPTIONS environment variable
to customize the resolv.conf options on a per-process basis, this
adds the same support to musl
---
src/network/resolvconf.c | 48 ++++++++++++++++++++++++++++++------------------
1 file changed, 30 insertions(+), 18 deletions(-)
diff --git a/src/network/resolvconf.c b/src/network/resolvconf.c
index 4c3e4c4b..c759ff61 100644
--- a/src/network/resolvconf.c
+++ b/src/network/resolvconf.c
@@ -5,6 +5,30 @@
#include <string.h>
#include <netinet/in.h>
+void __parse_resolv_opts(struct resolvconf *conf, char *opts)
+{
+ char *p, *z;
+
+ p = strstr(opts, "ndots:");
+ if (p && isdigit(p[6])) {
+ p += 6;
+ unsigned long x = strtoul(p, &z, 10);
+ if (z != p) conf->ndots = x > 15 ? 15 : x;
+ }
+ p = strstr(opts, "attempts:");
+ if (p && isdigit(p[9])) {
+ p += 9;
+ unsigned long x = strtoul(p, &z, 10);
+ if (z != p) conf->attempts = x > 10 ? 10 : x;
+ }
+ p = strstr(opts, "timeout:");
+ if (p && (isdigit(p[8]) || p[8]=='.')) {
+ p += 8;
+ unsigned long x = strtoul(p, &z, 10);
+ if (z != p) conf->timeout = x > 60 ? 60 : x;
+ }
+}
+
int __get_resolv_conf(struct resolvconf *conf, char *search, size_t search_sz)
{
char line[256];
@@ -38,24 +62,7 @@ int __get_resolv_conf(struct resolvconf *conf, char *search, size_t search_sz)
continue;
}
if (!strncmp(line, "options", 7) && isspace(line[7])) {
- p = strstr(line, "ndots:");
- if (p && isdigit(p[6])) {
- p += 6;
- unsigned long x = strtoul(p, &z, 10);
- if (z != p) conf->ndots = x > 15 ? 15 : x;
- }
- p = strstr(line, "attempts:");
- if (p && isdigit(p[9])) {
- p += 9;
- unsigned long x = strtoul(p, &z, 10);
- if (z != p) conf->attempts = x > 10 ? 10 : x;
- }
- p = strstr(line, "timeout:");
- if (p && (isdigit(p[8]) || p[8]=='.')) {
- p += 8;
- unsigned long x = strtoul(p, &z, 10);
- if (z != p) conf->timeout = x > 60 ? 60 : x;
- }
+ __parse_resolv_opts(conf, line);
continue;
}
if (!strncmp(line, "nameserver", 10) && isspace(line[10])) {
@@ -79,6 +86,11 @@ int __get_resolv_conf(struct resolvconf *conf, char *search, size_t search_sz)
memcpy(search, p, l+1);
}
+ char *res_opts_env;
+ if ((res_opts_env = getenv("RES_OPTIONS")) != NULL) {
+ __parse_resolv_opts(conf, res_opts_env);
+ }
+
__fclose_ca(f);
no_resolv_conf:
--
2.11.0
next reply other threads:[~2017-04-25 2:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-25 2:21 Stefan Sedich [this message]
2017-04-25 2:39 ` Rich Felker
2017-04-25 2:50 ` Kurt H Maier
2017-04-25 4:30 ` Stefan Sedich
2017-04-25 16:48 ` Rich Felker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170425022122.27281-1-stefan.sedich@gmail.com \
--to=stefan.sedich@gmail.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).