Making getenv more multi-threading--robust?

Stephan Bergmann sbergman@redhat.com
Thu Sep 13 10:57:00 GMT 2012


[I had initially erroneously sent this to libc-help instead.]

I stumbled over this when running the LibreOffice test suite and getting 
sporadic crashes in getenv(3).  It turns out that LibreOffice contains 
many places that call getenv (mostly to check whether to enable one 
tweak or another) at arbitrary times and from arbitrary threads, and 
apparently also contains the odd call to setenv etc. to modify the 
environment.

Though getenv is generally known to not be thread-safe, glibc already 
contains measures to make concurrent calls to setenv etc. thread-safe, 
so I wonder whether something like the attached 
0001-Prevent-races-when-getenv-walks-__environ-while-sete.patch would 
make sense.  While this would not solve my problems with 
(cross-platform) LibreOffice, it would help prevent glibc getenv crashes 
as demonstrated by the little program in the patch's commit message.

Stephan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Prevent-races-when-getenv-walks-__environ-while-sete.patch
Type: text/x-patch
Size: 3173 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20120913/1de50dc3/attachment.bin>


More information about the Libc-alpha mailing list