|Summary:||ASTERISK-01451: Reentrant gethostbyname|
|Reporter:||Olle Johansson (oej)||Labels:|
|Date Opened:||2004-04-22 04:22:36||Date Closed:||2004-09-25 02:49:42|
|Description:||gethostbyname() is not reentrant. This has been fixed on Linux by implementing gethostbyname_r() in ast_gethostbyname(). For FreeBSD - how do we solve this?|
****** ADDITIONAL INFORMATION ******
Important URL's and quotes:
The gethostbyname() man page mentions in the BUGS section:
"These functions use static data storage; if the data is needed for future
use, it should be copied before any subsequent calls overwrite it."
You should use the getaddrinfo() function which is reentrant, since
it doesn't use static data storage.
CVS Commit of reentrant code - don't know which version:
Article and patch
I don't know if the solution is the same for FreeBSD 4.9, 5.x and OpenBSD - it does look like it's specific for various systems.
|Comments:||By: Olle Johansson (oej) 2004-04-22 05:16:53|
This is how postgres solves it by not solving it really:
* Wrapper around gethostbyname() or gethostbyname_r() to mimic
* POSIX gethostbyname_r() behaviour, if it is not available.
pqGethostbyname(const char *name,
struct hostent * resbuf,
char *buf, size_t buflen,
struct hostent ** result,
#if defined(USE_THREADS) && defined(HAVE_GETHOSTBYNAME_R)
* broken (well early POSIX draft) gethostbyname_r() which returns
* 'struct hostent *'
*result = gethostbyname_r(name, resbuf, buf, buflen, herrno);
return (*result == NULL) ? -1 : 0;
/* no gethostbyname_r(), just use gethostbyname() */
*result = gethostbyname(name);
if (*result != NULL)
*herrno = h_errno;
By: Brian West (bkw918) 2004-04-22 10:40:36
We may very well have to fix it like that..
By: Mark Spencer (markster) 2004-04-22 12:17:09
I'm merging this in with the existing bug 1411 having to do with reentrant locking initializers which are also missing on BSD. We need some BSD person to step up to the plate and catchup the BSD port with the requisite changes for reentrancy.