summaryrefslogtreecommitdiffstats
path: root/lib/libc/asr/asr_resolver.c
diff options
context:
space:
mode:
authoreric <eric@openbsd.org>2012-08-18 11:19:51 +0000
committereric <eric@openbsd.org>2012-08-18 11:19:51 +0000
commit4a5082305ae892265cda902a457048c17960f23d (patch)
treed6385f3c434e27fe6efd1938c9e5b746464aed71 /lib/libc/asr/asr_resolver.c
parentallow other targets to work like install -> realinstall (diff)
downloadwireguard-openbsd-4a5082305ae892265cda902a457048c17960f23d.tar.xz
wireguard-openbsd-4a5082305ae892265cda902a457048c17960f23d.zip
Improve error reporting in getnameinfo_async() and getaddrinfo_async().
They do not have to deal with h_errno at all. Also, errno is only kept for EAI_SYSTEM. Small code cleanup while there. Adapt getnameinfo() and getaddrinfo() wrappers to correctly save errno and overwrite it in the EAI_SYSTEM case. General errno handling issue reported by mikeb@.
Diffstat (limited to 'lib/libc/asr/asr_resolver.c')
-rw-r--r--lib/libc/asr/asr_resolver.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/lib/libc/asr/asr_resolver.c b/lib/libc/asr/asr_resolver.c
index 6afd10a8d80..7de2e3acb5c 100644
--- a/lib/libc/asr/asr_resolver.c
+++ b/lib/libc/asr/asr_resolver.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: asr_resolver.c,v 1.5 2012/07/29 20:33:21 eric Exp $ */
+/* $OpenBSD: asr_resolver.c,v 1.6 2012/08/18 11:19:51 eric Exp $ */
/*
* Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
*
@@ -473,16 +473,21 @@ getaddrinfo(const char *hostname, const char *servname,
{
struct async *as;
struct async_res ar;
+ int saved_errno = errno;
as = getaddrinfo_async(hostname, servname, hints, NULL);
- if (as == NULL)
- return ((errno == ENOMEM) ? EAI_MEMORY : EAI_SYSTEM);
+ if (as == NULL) {
+ if (errno == ENOMEM) {
+ errno = saved_errno;
+ return (EAI_MEMORY);
+ }
+ return (EAI_SYSTEM);
+ }
async_run_sync(as, &ar);
- errno = ar.ar_errno;
- h_errno = ar.ar_h_errno;
*res = ar.ar_addrinfo;
+ errno = (ar.ar_gai_errno == EAI_SYSTEM) ? ar.ar_errno : saved_errno;
return (ar.ar_gai_errno);
}
@@ -493,16 +498,21 @@ getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host,
{
struct async *as;
struct async_res ar;
+ int saved_errno = errno;
as = getnameinfo_async(sa, salen, host, hostlen, serv, servlen, flags,
NULL);
- if (as == NULL)
- return ((errno == ENOMEM) ? EAI_MEMORY : EAI_SYSTEM);
+ if (as == NULL) {
+ if (errno == ENOMEM) {
+ errno = saved_errno;
+ return (EAI_MEMORY);
+ }
+ return (EAI_SYSTEM);
+ }
async_run_sync(as, &ar);
- errno = ar.ar_errno;
- h_errno = ar.ar_h_errno;
+ errno = (ar.ar_gai_errno == EAI_SYSTEM) ? ar.ar_errno : saved_errno;
return (ar.ar_gai_errno);
}