summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Purdie <rpurdie@linux.intel.com>2010-11-28 17:39:09 +0000
committerRichard Purdie <rpurdie@linux.intel.com>2010-12-09 13:16:14 +0000
commit0ba9a9fffee966ec912eec5fd52c468338560e6a (patch)
tree667079024d685b4f7ed1be59d3f23b7e00e97b2b
parent39dd60462c6d1e87f7c4105e1a3913e0aa54dba0 (diff)
downloadopenembedded-core-0ba9a9fffee966ec912eec5fd52c468338560e6a.tar.gz
openembedded-core-0ba9a9fffee966ec912eec5fd52c468338560e6a.tar.bz2
openembedded-core-0ba9a9fffee966ec912eec5fd52c468338560e6a.zip
bitbake: Overhaul environment handling
Currently, anything whitelisted in the environment makes it into the worker processes. This is undesireable and the worker environment should be as clean as possible. This patch adapts bitbake sosme variables are loaded into bitbake's datastore but not exported by default. Any variable can be exported by setting its export flag. Currently, this code only finalises the environment in he worker as doing so in the server means variables are unavailable in the worker. If we switch back to fork() calls instead of exec() this code will need revisting. Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
-rwxr-xr-xbitbake/bin/bitbake-runtask3
-rw-r--r--bitbake/lib/bb/cooker.py3
-rw-r--r--bitbake/lib/bb/data.py10
-rw-r--r--bitbake/lib/bb/runqueue.py1
-rw-r--r--bitbake/lib/bb/utils.py48
5 files changed, 48 insertions, 17 deletions
diff --git a/bitbake/bin/bitbake-runtask b/bitbake/bin/bitbake-runtask
index 88101a5c0f..9079f5725b 100755
--- a/bitbake/bin/bitbake-runtask
+++ b/bitbake/bin/bitbake-runtask
@@ -100,6 +100,9 @@ the_data = cooker.bb_cache.loadDataFull(fn, cooker.get_file_appends(fn), cooker.
cooker.bb_cache.setData(fn, buildfile, the_data)
cooker.bb_cache.handle_data(fn, cooker.status)
+exportlist = bb.utils.preserved_envvars_export_list()
+bb.utils.filter_environment(exportlist)
+
if taskname.endswith("_setscene"):
the_data.setVarFlag(taskname, "quieterrors", "1")
diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py
index 8c55e3e643..95f38f6236 100644
--- a/bitbake/lib/bb/cooker.py
+++ b/bitbake/lib/bb/cooker.py
@@ -918,7 +918,8 @@ class BBCooker:
def pre_serve(self):
# Empty the environment. The environment will be populated as
# necessary from the data store.
- bb.utils.empty_environment()
+ #bb.utils.empty_environment()
+ return
def post_serve(self):
bb.event.fire(CookerExit(), self.configuration.event_data)
diff --git a/bitbake/lib/bb/data.py b/bitbake/lib/bb/data.py
index fee10ccda4..d4d43fd8c8 100644
--- a/bitbake/lib/bb/data.py
+++ b/bitbake/lib/bb/data.py
@@ -161,10 +161,12 @@ def expandKeys(alterdata, readdata = None):
def inheritFromOS(d):
"""Inherit variables from the environment."""
+ exportlist = bb.utils.preserved_envvars_export_list()
for s in os.environ.keys():
try:
setVar(s, os.environ[s], d)
- setVarFlag(s, "export", True, d)
+ if s in exportlist:
+ setVarFlag(s, "export", True, d)
except TypeError:
pass
@@ -244,6 +246,12 @@ def export_vars(d):
pass
return ret
+def export_envvars(v, d):
+ for s in os.environ.keys():
+ if s not in v:
+ v[s] = os.environ[s]
+ return v
+
def emit_func(func, o=sys.__stdout__, d = init()):
"""Emits all items in the data store in a format such that it can be sourced by a shell."""
diff --git a/bitbake/lib/bb/runqueue.py b/bitbake/lib/bb/runqueue.py
index 3300db75cb..e26aa4e075 100644
--- a/bitbake/lib/bb/runqueue.py
+++ b/bitbake/lib/bb/runqueue.py
@@ -1062,6 +1062,7 @@ class RunQueueExecute:
the_data = self.cooker.bb_cache.loadDataFull(fn, self.cooker.get_file_appends(fn), self.cooker.configuration.data)
env = bb.data.export_vars(the_data)
+ env = bb.data.export_envvars(env, the_data)
taskdep = self.rqdata.dataCache.task_deps[fn]
if 'fakeroot' in taskdep and taskname in taskdep['fakeroot']:
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index 5419af6246..f468fafc12 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -465,13 +465,25 @@ def sha256_file(filename):
s.update(line)
return s.hexdigest()
-def preserved_envvars_list():
+# Variables which are preserved from the original environment *and* exported
+# into our worker context
+def preserved_envvars_export_list():
return [
- 'BBPATH',
- 'BB_PRESERVE_ENV',
- 'BB_ENV_WHITELIST',
- 'BB_ENV_EXTRAWHITE',
'BB_TASKHASH',
+ 'HOME',
+ 'LOGNAME',
+ 'PATH',
+ 'PWD',
+ 'SHELL',
+ 'TERM',
+ 'USER',
+ 'USERNAME',
+ ]
+
+# Variables which are preserved from the original environment *and* exported
+# into our worker context for interactive tasks (e.g. requiring X)
+def preserved_envvars_export_interactive_list():
+ return [
'COLORTERM',
'DBUS_SESSION_BUS_ADDRESS',
'DESKTOP_SESSION',
@@ -481,23 +493,25 @@ def preserved_envvars_list():
'GNOME_KEYRING_SOCKET',
'GPG_AGENT_INFO',
'GTK_RC_FILES',
- 'HOME',
- 'LANG',
- 'LOGNAME',
- 'PATH',
- 'PWD',
'SESSION_MANAGER',
- 'SHELL',
'SSH_AUTH_SOCK',
- 'TERM',
- 'USER',
- 'USERNAME',
- '_',
'XAUTHORITY',
'XDG_DATA_DIRS',
'XDG_SESSION_COOKIE',
]
+# Variables which are preserved from the original environment into the datastore
+def preserved_envvars_list():
+ v = [
+ 'BBPATH',
+ 'BB_PRESERVE_ENV',
+ 'BB_ENV_WHITELIST',
+ 'BB_ENV_EXTRAWHITE',
+ 'LANG',
+ '_',
+ ]
+ return v + preserved_envvars_export_list() + preserved_envvars_export_interactive_list()
+
def filter_environment(good_vars):
"""
Create a pristine environment for bitbake. This will remove variables that
@@ -518,6 +532,10 @@ def filter_environment(good_vars):
return removed_vars
+def create_intereactive_env(d):
+ for k in preserved_envvars_export_interactive_list():
+ os.setenv(k, bb.data.getVar(k, d, True))
+
def clean_environment():
"""
Clean up any spurious environment variables. This will remove any