summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorume <ume@FreeBSD.org>2005-04-05 18:25:23 +0000
committerume <ume@FreeBSD.org>2005-04-05 18:25:23 +0000
commitb0c9c2a388749a17c7e53ec55d5cfc76fa1eefc2 (patch)
treed418cffd007a12aee49c13d8fc8d937d212ac6c9 /lib
parentac4b9096b3b49b73828190512f14be0d7ca1a714 (diff)
downloadFreeBSD-src-b0c9c2a388749a17c7e53ec55d5cfc76fa1eefc2.zip
FreeBSD-src-b0c9c2a388749a17c7e53ec55d5cfc76fa1eefc2.tar.gz
make yp stuff re-entrant.
Obtained from: NetBSD
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/net/getaddrinfo.c41
1 files changed, 15 insertions, 26 deletions
diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c
index d125ffa7..0d73fd8 100644
--- a/lib/libc/net/getaddrinfo.c
+++ b/lib/libc/net/getaddrinfo.c
@@ -2172,8 +2172,6 @@ _files_getaddrinfo(rv, cb_data, ap)
}
#ifdef YP
-static char *__ypdomain;
-
/*ARGSUSED*/
static struct addrinfo *
_yphostent(line, pai)
@@ -2261,10 +2259,14 @@ _yp_getaddrinfo(rv, cb_data, ap)
{
struct addrinfo sentinel, *cur;
struct addrinfo *ai = NULL;
- static char *__ypcurrent;
- int __ypcurrentlen, r;
+ char *ypbuf;
+ int ypbuflen, r;
const char *name;
const struct addrinfo *pai;
+ char *ypdomain;
+
+ if (_yp_check(&ypdomain) == 0)
+ return NS_UNAVAIL;
name = va_arg(ap, char *);
pai = va_arg(ap, const struct addrinfo *);
@@ -2272,47 +2274,34 @@ _yp_getaddrinfo(rv, cb_data, ap)
memset(&sentinel, 0, sizeof(sentinel));
cur = &sentinel;
- THREAD_LOCK();
- if (!__ypdomain) {
- if (_yp_check(&__ypdomain) == 0) {
- THREAD_UNLOCK();
- return NS_UNAVAIL;
- }
- }
- if (__ypcurrent)
- free(__ypcurrent);
- __ypcurrent = NULL;
-
/* hosts.byname is only for IPv4 (Solaris8) */
if (pai->ai_family == PF_UNSPEC || pai->ai_family == PF_INET) {
- r = yp_match(__ypdomain, "hosts.byname", name,
- (int)strlen(name), &__ypcurrent, &__ypcurrentlen);
+ r = yp_match(ypdomain, "hosts.byname", name,
+ (int)strlen(name), &ypbuf, &ypbuflen);
if (r == 0) {
struct addrinfo ai4;
ai4 = *pai;
ai4.ai_family = AF_INET;
- ai = _yphostent(__ypcurrent, &ai4);
+ ai = _yphostent(ypbuf, &ai4);
if (ai) {
cur->ai_next = ai;
while (cur && cur->ai_next)
cur = cur->ai_next;
}
}
+ free(ypbuf);
}
/* ipnodes.byname can hold both IPv4/v6 */
- r = yp_match(__ypdomain, "ipnodes.byname", name,
- (int)strlen(name), &__ypcurrent, &__ypcurrentlen);
+ r = yp_match(ypdomain, "ipnodes.byname", name,
+ (int)strlen(name), &ypbuf, &ypbuflen);
if (r == 0) {
- ai = _yphostent(__ypcurrent, pai);
- if (ai) {
+ ai = _yphostent(ypbuf, pai);
+ if (ai)
cur->ai_next = ai;
- while (cur && cur->ai_next)
- cur = cur->ai_next;
- }
+ free(ypbuf);
}
- THREAD_UNLOCK();
if (sentinel.ai_next == NULL) {
h_errno = HOST_NOT_FOUND;
OpenPOWER on IntegriCloud