I guess this is an OSX problem?  While looking at the configure tests,
I noticed that gethostbyname_r etc. are not used on Linux, even though
they're available.  The standard call is thread safe, but only because
glibc puts a lock around everything.

I wonder if for performance the *_r variants should always be preferred...?



On Apr 9, 2005 3:16 AM, Zoran Vasiljevic
<[EMAIL PROTECTED]> wrote:
> Update of /cvsroot/naviserver/naviserver/nsd
> In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21706
> 
> Modified Files:
>         dns.c
> Log Message:
> Fixed GetAddr when dealing with gethostbyname_r calls. In some cases
> we ended up in an infinite loop.
> 
> Index: dns.c
> ===================================================================
> RCS file: /cvsroot/naviserver/naviserver/nsd/dns.c,v
> retrieving revision 1.1.1.1
> retrieving revision 1.2
> diff -C2 -d -r1.1.1.1 -r1.2
> *** dns.c       16 Feb 2005 08:39:25 -0000      1.1.1.1
> --- dns.c       9 Apr 2005 09:16:15 -0000       1.2
> ***************
> *** 1,7 ****
>   /*
> !  * The contents of this file are subject to the AOLserver Public License
>    * Version 1.1 (the "License"); you may not use this file except in
>    * compliance with the License. You may obtain a copy of the License at
> !  * http://aolserver.com/.
>    *
>    * Software distributed under the License is distributed on an "AS IS"
> --- 1,7 ----
>   /*
> !  * The contents of this file are subject to the Mozilla Public License
>    * Version 1.1 (the "License"); you may not use this file except in
>    * compliance with the License. You may obtain a copy of the License at
> !  * http://mozilla.org/.
>    *
>    * Software distributed under the License is distributed on an "AS IS"
> ***************
> *** 347,354 ****
>               Tcl_DStringAppendElement(dsPtr, ns_inet_ntoa(
>                           ((struct sockaddr_in *) ptr->ai_addr)->sin_addr));
>               ptr = ptr->ai_next;
>           }
>           freeaddrinfo(res);
> -         status = NS_TRUE;
>       }
>       return status;
> --- 347,354 ----
>               Tcl_DStringAppendElement(dsPtr, ns_inet_ntoa(
>                           ((struct sockaddr_in *) ptr->ai_addr)->sin_addr));
> +             status = NS_TRUE;
>               ptr = ptr->ai_next;
>           }
>           freeaddrinfo(res);
>       }
>       return status;
> ***************
> *** 367,374 ****
>       char buf[2048];
>       int result;
> -     int i = 0;
>       int h_errnop;
>       int status = NS_FALSE;
> 
>   #if defined(HAVE_GETHOSTBYNAME_R_6)
>       result = gethostbyname_r(host, &he, buf, sizeof(buf), &res, &h_errnop);
> --- 367,375 ----
>       char buf[2048];
>       int result;
>       int h_errnop;
>       int status = NS_FALSE;
> 
> +     memset(buf, 0, sizeof(buf));
> +
>   #if defined(HAVE_GETHOSTBYNAME_R_6)
>       result = gethostbyname_r(host, &he, buf, sizeof(buf), &res, &h_errnop);
> ***************
> *** 385,389 ****
> 
>       if (result != 0) {
> !       LogError("gethostbyname_r", h_errnop);
>       } else {
>           ptr = (struct in_addr *) he.h_addr_list[i];
> --- 386,390 ----
> 
>       if (result != 0) {
> !         LogError("gethostbyname_r", h_errnop);
>       } else {
>           ptr = (struct in_addr *) he.h_addr_list[i];
> ***************
> *** 392,395 ****
> --- 393,397 ----
>               Tcl_DStringAppendElement(dsPtr, ns_inet_ntoa(ia));
>               status = NS_TRUE;
> +             ptr = (struct in_addr *) he.h_addr_list[++i];
>           }
>       }
> ***************
> *** 419,423 ****
>       he = gethostbyname(host);
>       if (he == NULL) {
> !       LogError("gethostbyname", h_errno);
>       } else {
>           ptr = (struct in_addr *) he.h_addr_list[i];
> --- 421,425 ----
>       he = gethostbyname(host);
>       if (he == NULL) {
> !         LogError("gethostbyname", h_errno);
>       } else {
>           ptr = (struct in_addr *) he.h_addr_list[i];
> ***************
> *** 426,429 ****
> --- 428,432 ----
>               Tcl_DStringAppendElement(dsPtr, ns_inet_ntoa(ia));
>               status = NS_TRUE;
> +             ptr = (struct in_addr *) he.h_addr_list[++i];
>           }
>       }
>

Reply via email to