Skip to content

Commit 93b942e

Browse files
committed
Add a method to set environment variables for child processes
iutil.setenv will manipulate a dictionary that is added to a copy of os.environ that is passed to Popen. This way environment variables can be made available to child processes without modifying the environment of the anaconda process, which is not thread safe. Use iutil.setenv in place of os.environment for a variety of environment variables not needed by the anaconda process.
1 parent 8fd9055 commit 93b942e

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

anaconda

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,14 +1146,14 @@ if __name__ == "__main__":
11461146
log.info("Failed to parse proxy \"%s\": %s", anaconda.proxy, e)
11471147
else:
11481148
# Set environmental variables to be used by pre/post scripts
1149-
os.environ["PROXY"] = proxy.noauth_url
1150-
os.environ["PROXY_USER"] = proxy.username or ""
1151-
os.environ["PROXY_PASSWORD"] = proxy.password or ""
1149+
iutil.setenv("PROXY", proxy.noauth_url)
1150+
iutil.setenv("PROXY_USER", proxy.username or "")
1151+
iutil.setenv("PROXY_PASSWORD", proxy.password or "")
11521152

11531153
# Variables used by curl, libreport, etc.
1154-
os.environ["http_proxy"] = proxy.url
1155-
os.environ["ftp_proxy"] = proxy.url
1156-
os.environ["HTTPS_PROXY"] = proxy.url
1154+
iutil.setenv("http_proxy", proxy.url)
1155+
iutil.setenv("ftp_proxy", proxy.url)
1156+
iutil.setenv("HTTPS_PROXY", proxy.url)
11571157

11581158
if flags.noverifyssl:
11591159
ksdata.method.noverifyssl = flags.noverifyssl

pyanaconda/iutil.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,27 @@
5050

5151
from pyanaconda.anaconda_log import program_log_lock
5252

53+
_child_env = {}
54+
55+
def setenv(name, value):
56+
""" Set an environment variable to be used by child processes.
57+
58+
This method does not modify os.environ for the running process, which
59+
is not thread-safe. If setenv has already been called for a particular
60+
variable name, the old value is overwritten.
61+
62+
:param str name: The name of the environment variable
63+
:param str value: The value of the environment variable
64+
"""
65+
66+
_child_env[name] = value
67+
5368
def augmentEnv():
5469
env = os.environ.copy()
5570
env.update({"LC_ALL": "C",
5671
"ANA_INSTALL_PATH": getSysroot()
5772
})
73+
env.update(_child_env)
5874
return env
5975

6076
_root_path = "/mnt/sysimage"

pyanaconda/rescue.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def doRescue(intf, rescue_mount, ksdata):
383383
# set a library path to use mounted fs
384384
libdirs = os.environ.get("LD_LIBRARY_PATH", "").split(":")
385385
mounted = map(lambda dir: "/mnt/sysimage%s" % dir, libdirs)
386-
os.environ["LD_LIBRARY_PATH"] = ":".join(libdirs + mounted)
386+
iutil.setenv("LD_LIBRARY_PATH", ":".join(libdirs + mounted))
387387

388388
# find groff data dir
389389
gversion = None
@@ -401,8 +401,8 @@ def doRescue(intf, rescue_mount, ksdata):
401401

402402
if gversion is not None:
403403
gpath = "/mnt/sysimage/usr/share/groff/"+gversion
404-
os.environ["GROFF_FONT_PATH"] = gpath + '/font'
405-
os.environ["GROFF_TMAC_PATH"] = "%s:/mnt/sysimage/usr/share/groff/site-tmac" % (gpath + '/tmac',)
404+
iutil.setenv("GROFF_FONT_PATH", gpath + '/font')
405+
iutil.setenv("GROFF_TMAC_PATH", "%s:/mnt/sysimage/usr/share/groff/site-tmac" % (gpath + '/tmac',))
406406

407407
# do we have bash?
408408
try:

pyanaconda/ui/gui/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ def _widgetScale(self):
542542
if monitor_height_px >= 1200 and monitor_dpi_x > 192 and monitor_dpi_y > 192:
543543
display.set_window_scale(2)
544544
# Export the scale so that Gtk programs launched by anaconda are also scaled
545-
os.environ["GDK_SCALE"] = "2"
545+
iutil.setenv("GDK_SCALE", 2)
546546

547547
def _convertSignals(self):
548548
# What tends to happen when we receive a signal is that the signal will

0 commit comments

Comments
 (0)