Hi,

gethostbyname() being not thead-safe is a well know problem, most (all ?) implementations of this function use static storage.

Alternative is gethostbyname_r(), but it's really not portable, freebsd doesn't support gethostbyname_r as far as I know.

Furthermore, getaddrinfo() is supposed to be thread-safe, but if I remember correctly, previous version of freebsd (4.x ?) used a non thread-safe getaddrinfo() implementation.

IMHO, the best way to use gethostbyname() call is protect it with some lock mecanism:

LOCK();
hp = gethostbyname(...);
[...]
UNLOCK();

Bye.

Meadele Mathieu.


Gary McKinney wrote:
OK - I FINALLY found something on the gethostbyname() function not being thread safe....

http://lists.freebsd.org/pipermail/freebsd-threads/2004-February/001645.html

According to the info I read the gethostbyname() function uses static storage so if it is called in a threaded environment it is possible (and most likely probable) the information would be overwritten by a second call by another thread before it was read back out by the calling thread - the message goes on to say there *IS* a thread safe re-entrant function ( getaddrinfo() function) which should be used in a threaded environment to alleviate the "problem"...

I realize this is probably not the answer people are wanting to see (it would require some changes to the autoconf scripts to take into account FreeBSD vs other os types) but apparently that is the tack the FreeBSD community took to fix this problem...
Gary N. McKinney


Network Administrator
Computer Services Dept.
Brevard County Library System



---------- Original Message ----------------------------------
From: [EMAIL PROTECTED] (Paul Hampson)
Reply-To: [EMAIL PROTECTED]
Date:  Thu, 22 Apr 2004 02:06:02 +1000


On Wed, Apr 21, 2004 at 08:49:47AM -0400, Gary McKinney wrote:

I realize this is not a direct FreeRadius issue but possibly could be indirectly 
related if the
actual problem still exists with thread locking...

I checked the FreeBSD site for any PR listings for what you have described... did not find
anything - have you checked against the latest release of FreeBSD for the problem???

http://lists.cistron.nl/archives/freeradius-users/2003/09/frm00212.html * http://lists.cistron.nl/archives/freeradius-users/2003/09/msg00212.html http://lists.cistron.nl/archives/freeradius-users/2003/09/frm00434.html http://lists.cistron.nl/archives/freeradius-devel/2003/09/frm00093.html

_I_ haven't tested against the lastest release of FreeBSD. I'd welcome
any improvements to the thread-safety of FreeRADIUS, so if you want to
test it out and suggest changes that don't break any other versions of
FreeBSD, any other BSD flavours, and (if possible) Tru64 and OS/X...

However, given that we're ramping up to a release, I'd rather not
duplicate the 0.9 series's tendancy to need autoconf fixes for
gethostby* immediately after _each_ release. If we have something safe-
looking before we start the pre release cycle, and it gets _tested_ by
various FreeBSD and other bodies, then maybe. :-)

Whoops. While trawling the list archives from September I found someone
who asked me a question, and I never answered. :-( I hope he found
enlightenment eventually, and didn't leave us for Radiator.

--
Paul "TBBle" Hampson, on an alternate email client.

- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
---
[This E-mail scanned for viruses by Declude Ant-Virus Scanner]






________________________________________________________________
Sent via the KillerWebMail system at mail.brev.org





- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html



- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html

Reply via email to