Bug 18824

Summary: gethostbyname is not thread safe
Product: Base System Reporter: hook <hook>
Component: kernAssignee: freebsd-threads (Nobody) <threads>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   

Description hook 2000-05-26 07:50:00 UTC
The gethostbyname() is not thread safe. It causes lock ups if compiled with threads. It would be helpful if this is mentioned in the docs or if a thread-safe version is provided (gethostbyname_r ?)

How-To-Repeat: man gethostbyname
try to find any mention of threads on the page.
Comment 1 Kris Kennaway freebsd_committer freebsd_triage 2003-07-13 02:40:03 UTC
Responsible Changed
From-To: freebsd-bugs->freebsd-threads

Assign to threads mailing list
Comment 2 Craig Rodrigues 2004-02-16 17:33:41 UTC
> The gethostbyname() is not thread safe. It causes lock ups if
>compiled with threads. It would be helpful if this is mentioned in
>the docs or if a thread-safe version is provided (gethostbyname_r
>?)

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.

I think this PR should be closed.

-- 
Craig Rodrigues        
rodrigc@crodrigues.org
Comment 3 David Xu freebsd_committer freebsd_triage 2005-11-11 08:40:49 UTC
State Changed
From-To: open->closed

I think it was fixed in 6.0, it is thread safe: 

> These functions use a thread-specific data storage; if the data is needed 
> for future use, it should be copied before any subsequent calls overwrite 
> it.