samba shares access issue in Solaris from a MT program

David Collier-Brown davec-b at
Tue Sep 28 15:32:17 GMT 2004

   Just a followup to this fix for the team:  in the discussion
below, we've used the Solaris cc option "-mt" as a short form.
Setting it does two things:
	it sets -D_REENTRANT on the compiler command line
	it adds -lthread to the library list
   Setting -D_REENTRANT causes a number of small changes to
support reentrant and/or threaded code, the relevant part
being defining errno to be ___errno(), the thread-safe
errno function.

   So in principle, all that needs to change is the generated
make line for, from

	@echo Linking libsmbclient shared library $@
           	$(KRB5LIBS) $(LDAP_LIBS) \
		-h `basename $@`.$(LIBSMBCLIENT_MAJOR)

	@echo Linking libsmbclient shared library $@
           	$(KRB5LIBS) $(LDAP_LIBS) -lthread \
		-h `basename $@`.$(LIBSMBCLIENT_MAJOR)

... for Solaris versions up to 9. On Solaris 10, you don't
need to add -lthread, as it was folded into the standard
c library.

   Who's the configure guru on the team? (:-))


David Collier-Brown wrote:
> On Fri, 24 Sep 2004, Narayana Pattipati wrote:
>> [Nice description of problem redacted.]
>>> If samba is build with "-mt" flags, then the errno will be pointed
>>> to __errno() macro, instead of global errno, and thread executing samba
>>> code will be able to access correct errno.
>>> I have few open questions based on this:
>>> a) I read from samba site that its not MT safe. But since the code 
>>> runs in
>>>   one thread only, is it OK to build samba with "-mt" compiler flags ?
>>>   What would be the side effects if samba is build with -mt compiler
>>>   flags ?
> Richard Sharpe wrote:D>
>> I cannot see any problems with this, off my head.
>     From my experience with the compiler/linkers
>     on Sun, the only substantiative change is the
>     use of a thread-aware errno mechanism. If the
>     program is unthreaded, the errno will work
>     normally even with -mt specified.
>     Of course, it is the responsibility of the
>     caller to protect the library against concurrent
>     calls via locking, but that and -mt are what
>     we've used in the past to make non-thread-safe
>     libraries usable.
>     I'd like to suggest that the configure script
>     be changed to add -mt to the solaris linker
>     options for Solaris (only).
> --dave
> ps: would you like this submitted via bugzilla,for your records?
> -- 
> David Collier-Brown,  | Always do right. This will gratify
> davecb at    | some people and astonish the rest
>                       |                      -- Mark Twain

More information about the samba-technical mailing list