summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/getaddrinfo.c
diff options
context:
space:
mode:
authorray <>2007-02-15 04:25:35 +0000
committerray <>2007-02-15 04:25:35 +0000
commit9c6d816b59ddf3a4a800cde1e364d9045b286645 (patch)
tree54fc21c54b56f6fad7521349b7c215b39b54e812 /src/lib/libc/net/getaddrinfo.c
parent0c70b110e5fbbc2644ba8f7c65dacb9d1ac4e402 (diff)
downloadopenbsd-9c6d816b59ddf3a4a800cde1e364d9045b286645.tar.gz
openbsd-9c6d816b59ddf3a4a800cde1e364d9045b286645.tar.bz2
openbsd-9c6d816b59ddf3a4a800cde1e364d9045b286645.zip
Remove two mutexes by replacing getservbyname() and getservbyport()
calls with their reentrant versions. OK millert@.
Diffstat (limited to 'src/lib/libc/net/getaddrinfo.c')
-rw-r--r--src/lib/libc/net/getaddrinfo.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/lib/libc/net/getaddrinfo.c b/src/lib/libc/net/getaddrinfo.c
index 01cc3a292b..f462b2a2c9 100644
--- a/src/lib/libc/net/getaddrinfo.c
+++ b/src/lib/libc/net/getaddrinfo.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: getaddrinfo.c,v 1.58 2007/02/14 05:48:46 ray Exp $ */ 1/* $OpenBSD: getaddrinfo.c,v 1.59 2007/02/15 04:25:35 ray Exp $ */
2/* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ 2/* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */
3 3
4/* 4/*
@@ -826,11 +826,8 @@ static int
826get_port(struct addrinfo *ai, const char *servname, int matchonly) 826get_port(struct addrinfo *ai, const char *servname, int matchonly)
827{ 827{
828 const char *errstr, *proto; 828 const char *errstr, *proto;
829 struct servent *sp;
830 int port; 829 int port;
831 int allownumeric; 830 int allownumeric;
832 /* mutex is defined in getnameinfo.c */
833 extern void *__THREAD_NAME(serv_mutex);
834 831
835 if (servname == NULL) 832 if (servname == NULL)
836 return 0; 833 return 0;
@@ -864,6 +861,9 @@ get_port(struct addrinfo *ai, const char *servname, int matchonly)
864 return EAI_SERVICE; 861 return EAI_SERVICE;
865 port = htons(port); 862 port = htons(port);
866 } else { 863 } else {
864 struct servent sp;
865 struct servent_data sd;
866
867 if (errno == ERANGE) 867 if (errno == ERANGE)
868 return EAI_SERVICE; 868 return EAI_SERVICE;
869 if (ai->ai_flags & AI_NUMERICSERV) 869 if (ai->ai_flags & AI_NUMERICSERV)
@@ -881,12 +881,11 @@ get_port(struct addrinfo *ai, const char *servname, int matchonly)
881 break; 881 break;
882 } 882 }
883 883
884 _THREAD_PRIVATE_MUTEX_LOCK(serv_mutex); 884 (void)memset(&sd, 0, sizeof(sd));
885 sp = getservbyname(servname, proto); 885 if (getservbyname_r(servname, proto, &sp, &sd) == -1)
886 _THREAD_PRIVATE_MUTEX_UNLOCK(serv_mutex);
887 if (sp == NULL)
888 return EAI_SERVICE; 886 return EAI_SERVICE;
889 port = sp->s_port; 887 port = sp.s_port;
888 endservent_r(&sd);
890 } 889 }
891 890
892 if (!matchonly) { 891 if (!matchonly) {