improved thread safety?

Jelmer Vernooij jelmer at
Sat Jan 19 17:13:41 GMT 2008

Am Samstag, den 19.01.2008, 11:43 -0500 schrieb David Collier-Brown:
> At the expense of writing you a long answer rather than a short one,
> samba 4 uses the following functions which are mt-unsafe on Solaris
> and other standard-compliant systems:
Thanks, this is very useful.

> 	gethostbyaddr
> 	gethostbyname
I've filed bugs about these two.

> 	getopt
The calls to getopt() are not in code that uses threads or is used in

> 	getpass
We do use this in library code (credentials code), but I'm not quite
sure how to fix this without using locks. There's only one prompt you
can display at the same time, anyway.

> 	getservbyport
This is only used in the replacement code.

> 	inet_addr
I don't see why this one would be thread-unsafe.

> 	inet_ntoa
I've filed a bug about this one.

> 	pclose
> 	popen
Using grep, I couldn't find any references to popen/pclose. 

> 	initgroups
I'm not sure why this would be thread unsafe.

> 	random
> 	srandom
I'm not sure what to do about these. Are there any better alternatives?

> 	system
This isn't used by any code that uses threads or any library code except
the fault handling.

> I have a tool which finds these, and it found 290 lines of them.
> such as:
> "GIT/v4-0-test/source/lib/replace/getaddrinfo.c", line 110: gethostbyaddr
> # gethostbyaddr
> #      gethostbyaddr - network host database functions
> #      MT-Level: MT-Unsafe
The code in lib/replace/ is meant to provide replacements for functions
on platforms that don't have them and may use thread-unsafe functions to
implement them. Other parts of Samba should not use thread-unsafe
functions but instead rely on the thread-safe functions provided by the
system or lib/replace.

> The non-comment lines are in error-message format, to make it
> easy to use vim or emacs to review them all, and see if the
> code around them uses locks or other techniques to make them
> survive multi-threading.
> Send me mail if you want data on mt-unsafe, non-posix, or
> 32-bit-only only code: the tool is really for porting, but
> can inspect for all sorts of other things. 
Yeah, I would definitely be interested in that. Is this tool freely
available somewhere? It would be interesting to have it running as part
of the build process, testsuite or the buildfarm.



Jelmer Vernooij <jelmer at> -
Jabber: jelmer at
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 307 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url :

More information about the samba-technical mailing list