utils: orig_environ cleans LD_LIBRARY_PATH

LD_LIBRARY_PATH is set earlier than some of the other environment
variables like PATH or PYTHONPATH, so trying to save a clean version in
snapcraft is not viable.  Remove it here.
This commit is contained in:
Dan Bungert 2023-03-30 16:34:12 -06:00
parent 92ac6544cd
commit 1d9ad848fe
2 changed files with 9 additions and 0 deletions

View File

@ -40,10 +40,16 @@ class TestOrigEnviron(SubiTestCase):
expected = {}
self.assertEqual(expected, orig_environ(env))
def test_no_ld_library_path(self):
env = {'LD_LIBRARY_PATH': 'a'}
expected = {}
self.assertEqual(expected, orig_environ(env))
def test_practical(self):
snap = '/snap/subiquity/1234'
env = {
'TERM': 'linux',
'LD_LIBRARY_PATH': '/var/lib/snapd/lib/gl',
'PYTHONIOENCODING_ORIG': '',
'PYTHONIOENCODING': 'utf-8',
'SUBIQUITY_ROOT_ORIG': '',

View File

@ -36,6 +36,8 @@ def _clean_env(env, *, locale=True):
def orig_environ(env):
"""Generate an environment dict that is suitable for use for running
programs that live outside the snap."""
if env is None:
env = os.environ
ret = env.copy()
@ -47,6 +49,7 @@ def orig_environ(env):
else:
del ret[key_to_restore]
del ret[key]
ret.pop('LD_LIBRARY_PATH', None)
return ret