[PATCH 0/9] Fix thread safety issues in the environment

David Shea dshea at redhat.com
Thu Feb 5 14:20:46 UTC 2015


Short version: environment variables cannot be set in a multi-threaded
environment. It is ridiculous, and it has been a problem since the environment
was invented, and no one has a solution for it, and computers are the absolute
worst.

There is one environment variable that was cannot get around having to set.
Python's gettext module, to determine the language to return, searches
$LANGUAGE, $LC_ALL, $LC_MESSAGES, and $LANG. This is completely different from
gettext() and friends in glibc, which, if there is nothing in $LANGUAGE, uses
the locale data set by setlocale, which is thread-safe. This means that if we
want translations to work in any python module that we do not control, we need
to modify the environment.

So, possible solutions:
  1) write thread-safe versions of get/set/put/unsetenv, shoehorn it in with
     $LD_PRELOAD
  2) don't set any environment variables at all after starting threads,
     monkey-patch the gettext module to do the right thing
  3) don't set most environment variables, cross fingers and burn some sage
     before setting environment variables

These patches implement #3.

The last one is just a bonus. Did you know that nm-connection-editor wasn't run
in the language the user selected, but it totally could be? Now it is.

All this needs to be ported to RHEL 7.2 with Related: rhbz#1188287

David Shea (9):
  Add a pylint module to look for modifications to the environment
  Set $DISPLAY before threads are started.
  Add a method to set environment variables for child processes
  Add a parameter to iutil.startProgram to extend the environment
  Avoid setting $LANG and $LANGUAGE, except where we can't
  Assume that a bunch of digits in a version number is a timestamp
  Do not set $TZ
  Set $LIBUSER_CONF early
  Add an option to startProgram to not reset the locale

 anaconda                                   |  61 +++++++++-------
 pyanaconda/constants.py                    |   3 +
 pyanaconda/ihelp.py                        |   2 +-
 pyanaconda/isys/__init__.py                |  17 +++--
 pyanaconda/iutil.py                        |  34 +++++++--
 pyanaconda/kickstart.py                    |  11 ++-
 pyanaconda/localization.py                 |  11 ++-
 pyanaconda/packaging/__init__.py           |   4 +-
 pyanaconda/rescue.py                       |   6 +-
 pyanaconda/timezone.py                     |   9 +++
 pyanaconda/ui/gui/__init__.py              |   2 +-
 pyanaconda/ui/gui/spokes/datetime_spoke.py |  10 +--
 pyanaconda/ui/gui/spokes/network.py        |   4 +-
 pyanaconda/ui/gui/spokes/welcome.py        |  36 ++++++++--
 pyanaconda/users.py                        |  25 +++----
 pyanaconda/vnc.py                          |  19 +++--
 scripts/anaconda-yum                       |   1 +
 tests/pylint/environ.py                    | 107 +++++++++++++++++++++++++++++
 tests/pylint/pylint-one.sh                 |   2 +-
 utils/handle-sshpw                         |   2 -
 widgets/configure.ac                       |   2 +-
 widgets/src/BaseWindow.c                   |   6 +-
 widgets/src/BaseWindow.h                   |   2 +-
 widgets/src/StandaloneWindow.c             |   5 +-
 widgets/src/StandaloneWindow.h             |   2 +-
 25 files changed, 284 insertions(+), 99 deletions(-)
 create mode 100644 tests/pylint/environ.py

-- 
2.1.0



More information about the anaconda-patches mailing list