Ensure only the filtered environment variables are inherited from the OS
The recent change which modified inheritFromOS to use the intial environment, rather than the current environment, introduced a bug such that variables which had been cleaned from the environment where still set in the data store. This patch changes things such that a list of approved environment variables is saved after the environment is cleaned and only the variables in this list are inherited in inheritFromOS. CC: James Limbouris <james.limbouris@gmail.com> CC: Chris Larson <clarson@kergoth.com> (Bitbake rev: cb6c07054e8baf94614713ec257c643b22266d75) Signed-off-by: Joshua Lock <josh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
parent
a6c48298b1
commit
61d83c6d6b
|
@ -31,9 +31,10 @@ def main(args):
|
||||||
console.setFormatter(format)
|
console.setFormatter(format)
|
||||||
logger.addHandler(console)
|
logger.addHandler(console)
|
||||||
|
|
||||||
|
initialenv = os.environ.copy()
|
||||||
bb.utils.clean_environment()
|
bb.utils.clean_environment()
|
||||||
|
|
||||||
cmds = Commands()
|
cmds = Commands(initialenv)
|
||||||
if args:
|
if args:
|
||||||
cmds.onecmd(' '.join(args))
|
cmds.onecmd(' '.join(args))
|
||||||
else:
|
else:
|
||||||
|
@ -42,9 +43,8 @@ def main(args):
|
||||||
|
|
||||||
|
|
||||||
class Commands(cmd.Cmd):
|
class Commands(cmd.Cmd):
|
||||||
def __init__(self):
|
def __init__(self, initialenv):
|
||||||
cmd.Cmd.__init__(self)
|
cmd.Cmd.__init__(self)
|
||||||
initialenv = os.environ.copy()
|
|
||||||
self.returncode = 0
|
self.returncode = 0
|
||||||
self.config = Config(parse_only=True)
|
self.config = Config(parse_only=True)
|
||||||
self.cooker = bb.cooker.BBCooker(self.config,
|
self.cooker = bb.cooker.BBCooker(self.config,
|
||||||
|
|
|
@ -169,7 +169,8 @@ class BBCooker:
|
||||||
if not self.server_registration_cb:
|
if not self.server_registration_cb:
|
||||||
bb.data.setVar("BB_WORKERCONTEXT", "1", self.configuration.data)
|
bb.data.setVar("BB_WORKERCONTEXT", "1", self.configuration.data)
|
||||||
|
|
||||||
bb.data.inheritFromOS(self.configuration.data, self.savedenv)
|
filtered_keys = bb.utils.approved_variables()
|
||||||
|
bb.data.inheritFromOS(self.configuration.data, self.savedenv, filtered_keys)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.parseConfigurationFiles(self.configuration.prefile,
|
self.parseConfigurationFiles(self.configuration.prefile,
|
||||||
|
|
|
@ -159,16 +159,17 @@ def expandKeys(alterdata, readdata = None):
|
||||||
ekey = todolist[key]
|
ekey = todolist[key]
|
||||||
renameVar(key, ekey, alterdata)
|
renameVar(key, ekey, alterdata)
|
||||||
|
|
||||||
def inheritFromOS(d, savedenv):
|
def inheritFromOS(d, savedenv, permitted):
|
||||||
"""Inherit variables from the initial environment."""
|
"""Inherit variables from the initial environment."""
|
||||||
exportlist = bb.utils.preserved_envvars_exported()
|
exportlist = bb.utils.preserved_envvars_exported()
|
||||||
for s in savedenv.keys():
|
for s in savedenv.keys():
|
||||||
try:
|
if s in permitted:
|
||||||
setVar(s, getVar(s, savedenv, True), d)
|
try:
|
||||||
if s in exportlist:
|
setVar(s, getVar(s, savedenv, True), d)
|
||||||
setVarFlag(s, "export", True, d)
|
if s in exportlist:
|
||||||
except TypeError:
|
setVarFlag(s, "export", True, d)
|
||||||
pass
|
except TypeError:
|
||||||
|
pass
|
||||||
|
|
||||||
def emit_var(var, o=sys.__stdout__, d = init(), all=False):
|
def emit_var(var, o=sys.__stdout__, d = init(), all=False):
|
||||||
"""Emit a variable to be sourced by a shell."""
|
"""Emit a variable to be sourced by a shell."""
|
||||||
|
|
|
@ -565,18 +565,27 @@ def create_interactive_env(d):
|
||||||
for k in preserved_envvars_exported_interactive():
|
for k in preserved_envvars_exported_interactive():
|
||||||
os.setenv(k, bb.data.getVar(k, d, True))
|
os.setenv(k, bb.data.getVar(k, d, True))
|
||||||
|
|
||||||
|
def approved_variables():
|
||||||
|
"""
|
||||||
|
Determine and return the list of whitelisted variables which are approved
|
||||||
|
to remain in the envrionment.
|
||||||
|
"""
|
||||||
|
approved = []
|
||||||
|
if 'BB_ENV_WHITELIST' in os.environ:
|
||||||
|
approved = os.environ['BB_ENV_WHITELIST'].split()
|
||||||
|
else:
|
||||||
|
approved = preserved_envvars()
|
||||||
|
if 'BB_ENV_EXTRAWHITE' in os.environ:
|
||||||
|
approved.extend(os.environ['BB_ENV_EXTRAWHITE'].split())
|
||||||
|
return approved
|
||||||
|
|
||||||
def clean_environment():
|
def clean_environment():
|
||||||
"""
|
"""
|
||||||
Clean up any spurious environment variables. This will remove any
|
Clean up any spurious environment variables. This will remove any
|
||||||
variables the user hasn't chose to preserve.
|
variables the user hasn't chosen to preserve.
|
||||||
"""
|
"""
|
||||||
if 'BB_PRESERVE_ENV' not in os.environ:
|
if 'BB_PRESERVE_ENV' not in os.environ:
|
||||||
if 'BB_ENV_WHITELIST' in os.environ:
|
good_vars = approved_variables()
|
||||||
good_vars = os.environ['BB_ENV_WHITELIST'].split()
|
|
||||||
else:
|
|
||||||
good_vars = preserved_envvars()
|
|
||||||
if 'BB_ENV_EXTRAWHITE' in os.environ:
|
|
||||||
good_vars.extend(os.environ['BB_ENV_EXTRAWHITE'].split())
|
|
||||||
filter_environment(good_vars)
|
filter_environment(good_vars)
|
||||||
|
|
||||||
def empty_environment():
|
def empty_environment():
|
||||||
|
|
Loading…
Reference in New Issue