diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2015-10-03 22:35:31 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2015-10-03 22:35:31 +0000 |
commit | 541f50fd0b754ff96269fad6d74c3d8901416bc8 (patch) | |
tree | 3477e77dbda285c0aadfef7682e2e79ac713593c /lib/libc/asr/asr.c | |
parent | 989f0d33fc32b4069f29d7d0fc1ead3c28052f4d (diff) |
Initially eric developers asr as a side-load style library for async DNS.
When it was integrated as the main resolver, a bunch of strange initialization
code remained. Start whittling away at this, piece by piece, to make it
more clear.
ok eric
Diffstat (limited to 'lib/libc/asr/asr.c')
-rw-r--r-- | lib/libc/asr/asr.c | 76 |
1 files changed, 13 insertions, 63 deletions
diff --git a/lib/libc/asr/asr.c b/lib/libc/asr/asr.c index 8d5300a2f61..1f6429f5109 100644 --- a/lib/libc/asr/asr.c +++ b/lib/libc/asr/asr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: asr.c,v 1.44 2015/10/03 09:57:30 eric Exp $ */ +/* $OpenBSD: asr.c,v 1.45 2015/10/03 22:35:30 deraadt Exp $ */ /* * Copyright (c) 2010-2012 Eric Faurot <eric@openbsd.org> * @@ -36,25 +36,11 @@ #include "asr_private.h" -#ifndef ASR_OPT_THREADSAFE -#define ASR_OPT_THREADSAFE 1 -#endif #ifndef ASR_OPT_HOSTALIASES #define ASR_OPT_HOSTALIASES 1 #endif -#ifndef ASR_OPT_ENVOPTS -#define ASR_OPT_ENVOPTS 1 -#endif -#ifndef ASR_OPT_RELOADCONF -#define ASR_OPT_RELOADCONF 1 -#endif -#ifndef ASR_OPT_ALTCONF -#define ASR_OPT_ALTCONF 1 -#endif -#if ASR_OPT_THREADSAFE #include "thread_private.h" -#endif #define DEFAULT_CONF "lookup file\n" #define DEFAULT_LOOKUP "lookup bind file" @@ -73,21 +59,16 @@ static int asr_parse_nameserver(struct sockaddr *, const char *); static int asr_ndots(const char *); static void pass0(char **, int, struct asr_ctx *); static int strsplit(char *, char **, int); -#if ASR_OPT_ENVOPTS static void asr_ctx_envopts(struct asr_ctx *); -#endif -#if ASR_OPT_THREADSAFE static void *__THREAD_NAME(_asr); -#else -# define _THREAD_PRIVATE(a, b, c) (c) -#endif static struct asr *_asr = NULL; /* Allocate and configure an async "resolver". */ -void * -_asr_resolver(const char *conf) +static void * +_asr_resolver(void) { + const char *conf = _PATH_RESCONF; static int init = 0; struct asr *asr; @@ -102,36 +83,17 @@ _asr_resolver(const char *conf) if ((asr = calloc(1, sizeof(*asr))) == NULL) goto fail; -#if ASR_OPT_ALTCONF - /* If not setuid/setgid, allow to use an alternate config. */ - if (conf == NULL && !issetugid()) - conf = getenv("ASR_CONFIG"); -#endif - - if (conf == NULL) - conf = _PATH_RESCONF; - - if (conf[0] == '!') { - /* Use the rest of the string as config file */ + /* Use the given config file */ + asr->a_path = strdup(conf); + if (asr->a_path == NULL) + goto fail; + asr_check_reload(asr); + if (asr->a_ctx == NULL) { if ((asr->a_ctx = asr_ctx_create()) == NULL) goto fail; - if (asr_ctx_from_string(asr->a_ctx, conf + 1) == -1) + if (asr_ctx_from_string(asr->a_ctx, DEFAULT_CONF) == -1) goto fail; - } else { - /* Use the given config file */ - asr->a_path = strdup(conf); - if (asr->a_path == NULL) - goto fail; - asr_check_reload(asr); - if (asr->a_ctx == NULL) { - if ((asr->a_ctx = asr_ctx_create()) == NULL) - goto fail; - if (asr_ctx_from_string(asr->a_ctx, DEFAULT_CONF) == -1) - goto fail; -#if ASR_OPT_ENVOPTS - asr_ctx_envopts(asr->a_ctx); -#endif - } + asr_ctx_envopts(asr->a_ctx); } #ifdef DEBUG @@ -351,7 +313,7 @@ _asr_use_resolver(void *arg) priv = _THREAD_PRIVATE(_asr, _asr, &_asr); if (*priv == NULL) { DPRINT("setting up thread-local resolver\n"); - *priv = _asr_resolver(NULL); + *priv = _asr_resolver(); } asr = *priv; } @@ -409,17 +371,13 @@ static void asr_check_reload(struct asr *asr) { struct asr_ctx *ac; -#if ASR_OPT_RELOADCONF struct stat st; struct timespec ts; pid_t pid; -#endif if (asr->a_path == NULL) return; -#if ASR_OPT_RELOADCONF - pid = getpid(); if (pid != asr->a_pid) { asr->a_pid = pid; @@ -439,10 +397,6 @@ asr_check_reload(struct asr *asr) (ac = asr_ctx_create()) == NULL) return; asr->a_mtime = st.st_mtime; -#else - if ((ac = asr_ctx_create()) == NULL) - return; -#endif DPRINT("asr: reloading config file\n"); if (asr_ctx_from_file(ac, asr->a_path) == -1) { @@ -450,9 +404,7 @@ asr_check_reload(struct asr *asr) return; } -#if ASR_OPT_ENVOPTS asr_ctx_envopts(ac); -#endif if (asr->a_ctx) _asr_ctx_unref(asr->a_ctx); asr->a_ctx = ac; @@ -752,7 +704,6 @@ asr_ctx_parse(struct asr_ctx *ac, const char *str) return (0); } -#if ASR_OPT_ENVOPTS /* * Check for environment variables altering the configuration as described * in resolv.conf(5). Altough not documented there, this feature is disabled @@ -786,7 +737,6 @@ asr_ctx_envopts(struct asr_ctx *ac) asr_ctx_parse(ac, buf); } } -#endif /* * Parse a resolv.conf(5) nameserver string into a sockaddr. |