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 |
Priority: | Major | Regression? | No |
Status: | Closed/Complete | Components: | Core/General |
Versions: | Frequency of Occurrence | ||
Related Issues: | |||
Environment: | Attachments: | ||
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. ---- * http://news.gw.com/freebsd.threads/225 CVS Commit of reentrant code - don't know which version: * http://lists.freebsd.org/pipermail/cvs-src/2004-February/019269.html ----- Article and patch * http://kerneltrap.org/node/view/2395 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. */ int pqGethostbyname(const char *name, struct hostent * resbuf, char *buf, size_t buflen, struct hostent ** result, int *herrno) { #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; #else /* no gethostbyname_r(), just use gethostbyname() */ *result = gethostbyname(name); if (*result != NULL) return 0; else { *herrno = h_errno; return -1; } #endif } 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. |