1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-30 06:25:37 +03:00
systemd/man/threads-aware.xml
Zbigniew Jędrzejewski-Szmek 8c51e1520b man: add mention that libsystemd uses getenv()
See #26688: getenv() is not thread-safe, and could a possible source of
problems when a multi-threaded program calls setenv()/putenv()/unsetenv() in
parallel. It is not possible to avoid getenv() calls in general, since $PATH,
$LANG, $SHELL, $USER, $HOME, $TZ may need to be accessed at any time.
Add a warning to our docs so that people are aware of the issue.

Closes #26688. (Real fixes will need to be in glibc and gnome-shell or other
programs.)

The text is added to threads-aware.xml to be included in various places. By
including it in libsystemd-pkgconfig.xml, it is automatically added to all sd-*
pages. The text is also included explicitly in pages for a few other functions
which are call getenv().
2023-03-08 15:32:59 +01:00

24 lines
1.3 KiB
XML

<?xml version="1.0"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
<refsect1>
<para id="strict">All functions listed here are thread-agnostic and only a single specific thread may operate on a
given object during its entire lifetime. It's safe to allocate multiple independent objects and use each from a
specific thread in parallel. However, it's not safe to allocate such an object in one thread, and operate or free it
from any other, even if locking is used to ensure these threads don't operate on it at the very same time.</para>
<para id="safe">All functions listed here are thread-safe and may be called in parallel from multiple threads.</para>
<para id='getenv'>The code described here uses
<citerefentry project='man-pages'><refentrytitle>getenv</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
which is declared to be not multi-thread-safe. This means that the code calling the functions described
here must not call
<citerefentry project='man-pages'><refentrytitle>setenv</refentrytitle><manvolnum>3</manvolnum></citerefentry>
from a parallel thread. It is recommended to only do calls to <function>setenv()</function>
from an early phase of the program when no other threads have been started.</para>
</refsect1>