summaryrefslogtreecommitdiffstats
path: root/lib/libc/asr/asr.c
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2019-10-24 05:57:41 +0000
committerotto <otto@openbsd.org>2019-10-24 05:57:41 +0000
commitaf4d66b37c7394d6b39d0566d15c37785a0448b1 (patch)
tree438bb3654dfafebc14d1d5d174d9227cbf635222 /lib/libc/asr/asr.c
parentMake log tick interval independent of hz and reduce the frequency (diff)
downloadwireguard-openbsd-af4d66b37c7394d6b39d0566d15c37785a0448b1.tar.xz
wireguard-openbsd-af4d66b37c7394d6b39d0566d15c37785a0448b1.zip
Allow the caller of asr functions to create and use a specific context.
Diff from eric@ and florian@, commiting on their behalf since they are absent and we want to ride the minor shlib bump.
Diffstat (limited to 'lib/libc/asr/asr.c')
-rw-r--r--lib/libc/asr/asr.c43
1 files changed, 38 insertions, 5 deletions
diff --git a/lib/libc/asr/asr.c b/lib/libc/asr/asr.c
index 4891470b138..cd056c85719 100644
--- a/lib/libc/asr/asr.c
+++ b/lib/libc/asr/asr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: asr.c,v 1.61 2018/10/22 17:31:24 krw Exp $ */
+/* $OpenBSD: asr.c,v 1.62 2019/10/24 05:57:41 otto Exp $ */
/*
* Copyright (c) 2010-2012 Eric Faurot <eric@openbsd.org>
*
@@ -109,10 +109,14 @@ _asr_resolver(void)
void
_asr_resolver_done(void *arg)
{
- struct asr *asr = arg;
+ struct asr_ctx *ac = arg;
+ struct asr *asr;
struct asr **priv;
- if (asr == NULL) {
+ if (ac) {
+ _asr_ctx_unref(ac);
+ return;
+ } else {
priv = _THREAD_PRIVATE(_asr, _asr, &_asr);
if (*priv == NULL)
return;
@@ -124,6 +128,30 @@ _asr_resolver_done(void *arg)
free(asr);
}
+void *
+asr_resolver_from_string(const char *str)
+{
+ struct asr_ctx *ac;
+
+ if ((ac = asr_ctx_create()) == NULL)
+ return NULL;
+
+ if (asr_ctx_from_string(ac, str) == -1) {
+ asr_ctx_free(ac);
+ return NULL;
+ }
+
+ return ac;
+}
+DEF_WEAK(asr_resolver_from_string);
+
+void
+asr_resolver_free(void *arg)
+{
+ _asr_ctx_unref(arg);
+}
+DEF_WEAK(asr_resolver_free);
+
/*
* Cancel an async query.
*/
@@ -309,10 +337,15 @@ _asr_async_free(struct asr_query *as)
struct asr_ctx *
_asr_use_resolver(void *arg)
{
- struct asr *asr = arg;
+ struct asr_ctx *ac = arg;
+ struct asr *asr;
struct asr **priv;
- if (asr == NULL) {
+ if (ac) {
+ asr_ctx_ref(ac);
+ return ac;
+ }
+ else {
DPRINT("using thread-local resolver\n");
priv = _THREAD_PRIVATE(_asr, _asr, &_asr);
if (*priv == NULL) {