nwrap: Add BSD libc support for gethost*_r functios.
authorRobin Hack <hack.robin@gmail.com>
Fri, 27 Mar 2015 14:51:11 +0000 (15:51 +0100)
committerMichael Adam <obnox@samba.org>
Mon, 11 Jan 2016 11:25:28 +0000 (12:25 +0100)
BSD libc stores data in thread local storage.

Signed-off-by: Robin Hack <hack.robin@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
lib/nss_wrapper/nss_wrapper.c

index b133e01425ee2bf704300e71a8cd60d21db74de6..f2c2d557af400bf76fbcc7b7caada8654743985d 100644 (file)
@@ -4746,8 +4746,14 @@ void endhostent(void)
 }
 #endif /* HAVE_SOLARIS_ENDHOSTENT */
 
+#ifdef BSD
+/* BSD implementation stores data in thread local storage but GLIBC does not */
+static __thread struct hostent user_he;
+static __thread struct nwrap_vector user_addrlist;
+#else
 static struct hostent user_he;
 static struct nwrap_vector user_addrlist;
+#endif /* BSD */
 static struct hostent *nwrap_gethostbyname(const char *name)
 {
        if (nwrap_files_gethostbyname(name, AF_UNSPEC, &user_he, &user_addrlist) == -1) {
@@ -4765,9 +4771,16 @@ struct hostent *gethostbyname(const char *name)
        return nwrap_gethostbyname(name);
 }
 
+/* This is a GNU extension - Also can be found on BSD systems */
 #ifdef HAVE_GETHOSTBYNAME2
+#ifdef BSD
+/* BSD implementation stores data in  thread local storage but GLIBC not */
+static __thread struct hostent user_he2;
+static __thread struct nwrap_vector user_addrlist2;
+#else
 static struct hostent user_he2;
 static struct nwrap_vector user_addrlist2;
+#endif /* BSD */
 static struct hostent *nwrap_gethostbyname2(const char *name, int af)
 {
        if (nwrap_files_gethostbyname(name, af, &user_he2, &user_addrlist2) == -1) {