improved thread safety?

David Collier-Brown davecb at sun.com
Sat Jan 19 19:30:56 GMT 2008



Jelmer Vernooij wrote:
> 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
> libraries. 
> 
> 
>>	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.
	Aha: I checked the man page, and the function is mt-save. I've
	fixed the database for it and initgroups, below...

	Thanks, I've now complete  re-checked the database and found 
	several more 	functions where the MT-level had been corrected since
	Solaris 8.  Ecvt, fcvt and popen, for example!
	


> 
> 
>>	inet_ntoa
> 
> I've filed a bug about this one.
> 
> 
>>	pclose
>>	popen
> 
> Using grep, I couldn't find any references to popen/pclose. 
	fixed
> 
> 
>>	initgroups
> 
> I'm not sure why this would be thread unsafe.
	fixed
> 
> 
>>	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.
> 
> Cheers,
> 
> Jelmer
> 

-- 
David Collier-Brown            | Always do right. This will gratify
Sun Microsystems, Toronto      | some people and astonish the rest
davecb at sun.com                 |                      -- Mark Twain
(800) 555-9786 x56583 cell: (647) 833-9377 home off: (416) 223-5943 


More information about the samba-technical mailing list