diff options
author | marc <> | 2003-01-28 04:58:00 +0000 |
---|---|---|
committer | marc <> | 2003-01-28 04:58:00 +0000 |
commit | 547ebab319b228b064cf5dcb3ff0ae1bf23d24a2 (patch) | |
tree | f57454716593fb3b68672505c6dccab6438498f1 /src/lib/libc/net/getnameinfo.c | |
parent | 98a78d57b176408b5aca87705f9681c5b155b47c (diff) | |
download | openbsd-547ebab319b228b064cf5dcb3ff0ae1bf23d24a2.tar.gz openbsd-547ebab319b228b064cf5dcb3ff0ae1bf23d24a2.tar.bz2 openbsd-547ebab319b228b064cf5dcb3ff0ae1bf23d24a2.zip |
thread safer libc (note: safer, not safe)
Access to the global _res structure replaced by pointers to a
per thread instance. If unthreaded the pointer is to the
global structure.
Also replaced a 64k stack array with malloc-ed memory so
threaded aps (with a default 64k stack) have a chance at working.
ok deraadt@
Diffstat (limited to 'src/lib/libc/net/getnameinfo.c')
-rw-r--r-- | src/lib/libc/net/getnameinfo.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/lib/libc/net/getnameinfo.c b/src/lib/libc/net/getnameinfo.c index 2311eba7a0..d3a9678cbd 100644 --- a/src/lib/libc/net/getnameinfo.c +++ b/src/lib/libc/net/getnameinfo.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: getnameinfo.c,v 1.25 2002/06/27 09:24:28 itojun Exp $ */ | 1 | /* $OpenBSD: getnameinfo.c,v 1.26 2003/01/28 04:58:00 marc Exp $ */ |
2 | /* $KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $ */ | 2 | /* $KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $ */ |
3 | 3 | ||
4 | /* | 4 | /* |
@@ -59,6 +59,8 @@ | |||
59 | #include <string.h> | 59 | #include <string.h> |
60 | #include <stddef.h> | 60 | #include <stddef.h> |
61 | 61 | ||
62 | #include "thread_private.h" | ||
63 | |||
62 | static const struct afd { | 64 | static const struct afd { |
63 | int a_af; | 65 | int a_af; |
64 | int a_addrlen; | 66 | int a_addrlen; |
@@ -106,6 +108,7 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) | |||
106 | int h_error; | 108 | int h_error; |
107 | char numserv[512]; | 109 | char numserv[512]; |
108 | char numaddr[512]; | 110 | char numaddr[512]; |
111 | _THREAD_PRIVATE_MUTEX(serv_mutex); | ||
109 | 112 | ||
110 | if (sa == NULL) | 113 | if (sa == NULL) |
111 | return EAI_FAIL; | 114 | return EAI_FAIL; |
@@ -140,8 +143,10 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) | |||
140 | if (flags & NI_NUMERICSERV) | 143 | if (flags & NI_NUMERICSERV) |
141 | sp = NULL; | 144 | sp = NULL; |
142 | else { | 145 | else { |
146 | _THREAD_PRIVATE_MUTEX_LOCK(serv_mutex); | ||
143 | sp = getservbyport(port, | 147 | sp = getservbyport(port, |
144 | (flags & NI_DGRAM) ? "udp" : "tcp"); | 148 | (flags & NI_DGRAM) ? "udp" : "tcp"); |
149 | _THREAD_PRIVATE_MUTEX_UNLOCK(serv_mutex); | ||
145 | } | 150 | } |
146 | if (sp) { | 151 | if (sp) { |
147 | if (strlen(sp->s_name) + 1 > servlen) | 152 | if (strlen(sp->s_name) + 1 > servlen) |
@@ -228,7 +233,9 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) | |||
228 | break; | 233 | break; |
229 | } | 234 | } |
230 | } else { | 235 | } else { |
236 | _THREAD_PRIVATE_MUTEX_LOCK(serv_mutex); | ||
231 | hp = gethostbyaddr(addr, afd->a_addrlen, afd->a_af); | 237 | hp = gethostbyaddr(addr, afd->a_addrlen, afd->a_af); |
238 | _THREAD_PRIVATE_MUTEX_UNLOCK(serv_mutex); | ||
232 | h_error = h_errno; | 239 | h_error = h_errno; |
233 | 240 | ||
234 | if (hp) { | 241 | if (hp) { |