Merge pull request #46011 from terminalmage/fix-solaris-runas

cmdmod.py: runas workaround for platforms that don't set a USER env var
This commit is contained in:
Nicole Thomas 2018-02-13 17:03:10 -05:00 committed by GitHub
commit 1f44e285dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -423,6 +423,10 @@ def _run(cmd,
env_encoded = env_encoded.encode(__salt_system_encoding__)
env_runas = dict(list(zip(*[iter(env_encoded.split(b'\0'))]*2)))
env_runas.update(env)
# Fix platforms like Solaris that don't set a USER env var in the
# user's default environment as obtained above.
if env_runas.get('USER') != runas:
env_runas['USER'] = runas
env = env_runas
# Encode unicode kwargs to filesystem encoding to avoid a
# UnicodeEncodeError when the subprocess is invoked.