summaryrefslogtreecommitdiffstats
path: root/bitbake
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 /bitbake
parent39dd60462c6d1e87f7c4105e1a3913e0aa54dba0 (diff)
downloadpoky-0ba9a9fffee966ec912eec5fd52c468338560e6a.tar.gz
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>
Diffstat (limited to 'bitbake')
-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.
100cooker.bb_cache.setData(fn, buildfile, the_data) 100cooker.bb_cache.setData(fn, buildfile, the_data)
101cooker.bb_cache.handle_data(fn, cooker.status) 101cooker.bb_cache.handle_data(fn, cooker.status)
102 102
103exportlist = bb.utils.preserved_envvars_export_list()
104bb.utils.filter_environment(exportlist)
105
103if taskname.endswith("_setscene"): 106if taskname.endswith("_setscene"):
104 the_data.setVarFlag(taskname, "quieterrors", "1") 107 the_data.setVarFlag(taskname, "quieterrors", "1")
105 108
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:
918 def pre_serve(self): 918 def pre_serve(self):
919 # Empty the environment. The environment will be populated as 919 # Empty the environment. The environment will be populated as
920 # necessary from the data store. 920 # necessary from the data store.
921 bb.utils.empty_environment() 921 #bb.utils.empty_environment()
922 return
922 923
923 def post_serve(self): 924 def post_serve(self):
924 bb.event.fire(CookerExit(), self.configuration.event_data) 925 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):
161 161
162def inheritFromOS(d): 162def inheritFromOS(d):
163 """Inherit variables from the environment.""" 163 """Inherit variables from the environment."""
164 exportlist = bb.utils.preserved_envvars_export_list()
164 for s in os.environ.keys(): 165 for s in os.environ.keys():
165 try: 166 try:
166 setVar(s, os.environ[s], d) 167 setVar(s, os.environ[s], d)
167 setVarFlag(s, "export", True, d) 168 if s in exportlist:
169 setVarFlag(s, "export", True, d)
168 except TypeError: 170 except TypeError:
169 pass 171 pass
170 172
@@ -244,6 +246,12 @@ def export_vars(d):
244 pass 246 pass
245 return ret 247 return ret
246 248
249def export_envvars(v, d):
250 for s in os.environ.keys():
251 if s not in v:
252 v[s] = os.environ[s]
253 return v
254
247def emit_func(func, o=sys.__stdout__, d = init()): 255def emit_func(func, o=sys.__stdout__, d = init()):
248 """Emits all items in the data store in a format such that it can be sourced by a shell.""" 256 """Emits all items in the data store in a format such that it can be sourced by a shell."""
249 257
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:
1062 the_data = self.cooker.bb_cache.loadDataFull(fn, self.cooker.get_file_appends(fn), self.cooker.configuration.data) 1062 the_data = self.cooker.bb_cache.loadDataFull(fn, self.cooker.get_file_appends(fn), self.cooker.configuration.data)
1063 1063
1064 env = bb.data.export_vars(the_data) 1064 env = bb.data.export_vars(the_data)
1065 env = bb.data.export_envvars(env, the_data)
1065 1066
1066 taskdep = self.rqdata.dataCache.task_deps[fn] 1067 taskdep = self.rqdata.dataCache.task_deps[fn]
1067 if 'fakeroot' in taskdep and taskname in taskdep['fakeroot']: 1068 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):
465 s.update(line) 465 s.update(line)
466 return s.hexdigest() 466 return s.hexdigest()
467 467
468def preserved_envvars_list(): 468# Variables which are preserved from the original environment *and* exported
469# into our worker context
470def preserved_envvars_export_list():
469 return [ 471 return [
470 'BBPATH',
471 'BB_PRESERVE_ENV',
472 'BB_ENV_WHITELIST',
473 'BB_ENV_EXTRAWHITE',
474 'BB_TASKHASH', 472 'BB_TASKHASH',
473 'HOME',
474 'LOGNAME',
475 'PATH',
476 'PWD',
477 'SHELL',
478 'TERM',
479 'USER',
480 'USERNAME',
481 ]
482
483# Variables which are preserved from the original environment *and* exported
484# into our worker context for interactive tasks (e.g. requiring X)
485def preserved_envvars_export_interactive_list():
486 return [
475 'COLORTERM', 487 'COLORTERM',
476 'DBUS_SESSION_BUS_ADDRESS', 488 'DBUS_SESSION_BUS_ADDRESS',
477 'DESKTOP_SESSION', 489 'DESKTOP_SESSION',
@@ -481,23 +493,25 @@ def preserved_envvars_list():
481 'GNOME_KEYRING_SOCKET', 493 'GNOME_KEYRING_SOCKET',
482 'GPG_AGENT_INFO', 494 'GPG_AGENT_INFO',
483 'GTK_RC_FILES', 495 'GTK_RC_FILES',
484 'HOME',
485 'LANG',
486 'LOGNAME',
487 'PATH',
488 'PWD',
489 'SESSION_MANAGER', 496 'SESSION_MANAGER',
490 'SHELL',
491 'SSH_AUTH_SOCK', 497 'SSH_AUTH_SOCK',
492 'TERM',
493 'USER',
494 'USERNAME',
495 '_',
496 'XAUTHORITY', 498 'XAUTHORITY',
497 'XDG_DATA_DIRS', 499 'XDG_DATA_DIRS',
498 'XDG_SESSION_COOKIE', 500 'XDG_SESSION_COOKIE',
499 ] 501 ]
500 502
503# Variables which are preserved from the original environment into the datastore
504def preserved_envvars_list():
505 v = [
506 'BBPATH',
507 'BB_PRESERVE_ENV',
508 'BB_ENV_WHITELIST',
509 'BB_ENV_EXTRAWHITE',
510 'LANG',
511 '_',
512 ]
513 return v + preserved_envvars_export_list() + preserved_envvars_export_interactive_list()
514
501def filter_environment(good_vars): 515def filter_environment(good_vars):
502 """ 516 """
503 Create a pristine environment for bitbake. This will remove variables that 517 Create a pristine environment for bitbake. This will remove variables that
@@ -518,6 +532,10 @@ def filter_environment(good_vars):
518 532
519 return removed_vars 533 return removed_vars
520 534
535def create_intereactive_env(d):
536 for k in preserved_envvars_export_interactive_list():
537 os.setenv(k, bb.data.getVar(k, d, True))
538
521def clean_environment(): 539def clean_environment():
522 """ 540 """
523 Clean up any spurious environment variables. This will remove any 541 Clean up any spurious environment variables. This will remove any