From 4f8057034a82f239629df8cfe8dde35d99cc4b77 Mon Sep 17 00:00:00 2001 From: vraatikka Date: Thu, 5 Sep 2013 19:42:59 +0300 Subject: [PATCH] Protected temporarily with spinlock gethostbyname which is not thread safe. This should be changed permanently so that gethostbyname is replaced with getaddrinfo. --- server/core/gw_utils.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/core/gw_utils.c b/server/core/gw_utils.c index 104a890e3..92aab8ee8 100644 --- a/server/core/gw_utils.c +++ b/server/core/gw_utils.c @@ -36,6 +36,8 @@ #include #include +SPINLOCK tmplock = SPINLOCK_INIT; + /** * Set IP address in socket structure in_addr * @@ -44,7 +46,12 @@ */ void setipaddress(struct in_addr *a, char *p) { - struct hostent *h = gethostbyname(p); + struct hostent *h; + + spinlock_acquire(&tmplock); + h = gethostbyname(p); + spinlock_release(&tmplock); + if (h == NULL) { if ((a->s_addr = inet_addr(p)) == -1) { fprintf(stderr, "unknown or invalid address [%s]\n", p);