[talk] Is getaddrinfo thread-safe on OS X?

Steve steve.b at osfda.org
Mon Jan 4 09:00:56 EST 2016


Sometimes they do things like that for backlevel compatibility; so 
single threaded apps that rely on that global don't immediately break.
The question is: does ds_getaddrinfo _rely_ on that variable?

I doubt it; but it's _possible_ you found an oversight!


On 1/3/2016 10:57 AM, A. Jesse Jiryu Davis wrote:
> Thanks for the pointers, with your help I'm making progress. I think I 
> found the source for Apple's getaddrinfo.
>
> In Apple's Libinfo version 222.4.12, the man page says getaddrinfo 
> isn't thread-safe:
>
> http://www.opensource.apple.com/source/Libinfo/Libinfo-222.4.12/lookup.subproj/getaddrinfo.3
>
> And here's its source:
>
> http://www.opensource.apple.com/source/Libinfo/Libinfo-222.4.12/lookup.subproj/getaddrinfo.c
>
> Glancing at the source naïvely, I might see the data race: getaddrinfo 
> calls gai_lookupd, which reads and writes the global static variable 
> "gai_proc". I can't see what will go wrong as a result of the race, 
> but it sure LOOKS bad. =)
>
> In the next release, version 278, the thread-safety warning is gone 
> from the man page:
>
> http://www.opensource.apple.com/source/Libinfo/Libinfo-278/lookup.subproj/getaddrinfo.3
>
> And getaddrinfo is largely rewritten:
>
> http://www.opensource.apple.com/source/Libinfo/Libinfo-278/lookup.subproj/getaddrinfo.c
>
> It calls a new function, "ds_getaddrinfo". But ds_getaddrinfo still 
> accesses the global static variable "gai_proc"; I wonder why this is 
> considered thread-safe now?
>
> On Sun, Jan 3, 2016 at 12:14 AM, Siobhan Lynch <slynch2112 at me.com 
> <mailto:slynch2112 at me.com>> wrote:
>
>     OK… try and look at the revision histories of these three files:
>
>     *#include* *<sys/types.h>*
>     *#include* *<sys/socket.h>*
>     *#include* *<netdb.h>*
>
>
>     *-Trish*
>
>
>
>
>
> _______________________________________________
> talk mailing list
> talk at lists.nycbug.org
> http://lists.nycbug.org/mailman/listinfo/talk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.nycbug.org:8443/pipermail/talk/attachments/20160104/6ecaa644/attachment.htm>


More information about the talk mailing list