Openembedded Bitbake Development
 help / color / mirror / Atom feed
* [RFC PATCH 0/1] Don't include cleaned variables in inherited environment
@ 2011-08-13  0:58 Joshua Lock
  2011-08-13  0:58 ` [RFC PATCH 1/1] Ensure only the filtered environment variables are inherited from the OS Joshua Lock
  0 siblings, 1 reply; 3+ messages in thread
From: Joshua Lock @ 2011-08-13  0:58 UTC (permalink / raw)
  To: bitbake-devel

Per James Limbouris' report the pristine, saved environment is erroneously
added to the data store. This patch fixes this bug by passing a list of the
permitted variables to the inheritFromOS method and only inheriting those
which appear in the approved list.

Please review the following changes for suitability for inclusion. If you have
any objections or suggestions for improvement, please respond to the patches. If
you agree with the changes, please provide your Acked-by.

The following changes since commit b3ad7acebfad3063c3364f4492f53b25bf53cf81:

  lib/bb/ui/crumbs/hobprefs: fix erroneous save/reparse (2011-08-12 17:48:13 +0100)

are available in the git repository at:
  git://github.com/incandescant/bitbake env
  https://github.com/incandescant/bitbake/tree/env

Joshua Lock (1):
  Ensure only the filtered environment variables are inherited from the
    OS

 bin/bitbake-layers |    6 +++---
 lib/bb/cooker.py   |    3 ++-
 lib/bb/data.py     |   15 ++++++++-------
 lib/bb/utils.py    |   23 ++++++++++++++++-------
 4 files changed, 29 insertions(+), 18 deletions(-)

-- 
1.7.6




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [RFC PATCH 1/1] Ensure only the filtered environment variables are inherited from the OS
  2011-08-13  0:58 [RFC PATCH 0/1] Don't include cleaned variables in inherited environment Joshua Lock
@ 2011-08-13  0:58 ` Joshua Lock
  2011-08-15  8:41   ` Richard Purdie
  0 siblings, 1 reply; 3+ messages in thread
From: Joshua Lock @ 2011-08-13  0:58 UTC (permalink / raw)
  To: bitbake-devel

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>
Signed-off-by: Joshua Lock <josh@linux.intel.com>
---
 bin/bitbake-layers |    6 +++---
 lib/bb/cooker.py   |    3 ++-
 lib/bb/data.py     |   15 ++++++++-------
 lib/bb/utils.py    |   23 ++++++++++++++++-------
 4 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/bin/bitbake-layers b/bin/bitbake-layers
index d9f95d1..3fdf567 100755
--- a/bin/bitbake-layers
+++ b/bin/bitbake-layers
@@ -28,9 +28,10 @@ default_cmd = 'show_appends'
 
 def main(args):
     logging.basicConfig(format='%(levelname)s: %(message)s')
+    initialenv = os.environ.copy()
     bb.utils.clean_environment()
 
-    cmds = Commands()
+    cmds = Commands(initialenv)
     if args:
         cmds.onecmd(' '.join(args))
     else:
@@ -39,9 +40,8 @@ def main(args):
 
 
 class Commands(cmd.Cmd):
-    def __init__(self):
+    def __init__(self, initialenv):
         cmd.Cmd.__init__(self)
-        initialenv = os.environ.copy()
         self.returncode = 0
         self.config = Config(parse_only=True)
         self.cooker = bb.cooker.BBCooker(self.config,
diff --git a/lib/bb/cooker.py b/lib/bb/cooker.py
index 1978750..a0fcc15 100644
--- a/lib/bb/cooker.py
+++ b/lib/bb/cooker.py
@@ -163,7 +163,8 @@ class BBCooker:
     def loadConfigurationData(self):
         self.configuration.data = bb.data.init()
 
-        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:
             self.parseConfigurationFiles(self.configuration.prefile,
diff --git a/lib/bb/data.py b/lib/bb/data.py
index 65144bf..ac0d880 100644
--- a/lib/bb/data.py
+++ b/lib/bb/data.py
@@ -159,16 +159,17 @@ def expandKeys(alterdata, readdata = None):
         ekey = todolist[key]
         renameVar(key, ekey, alterdata)
 
-def inheritFromOS(d, savedenv):
+def inheritFromOS(d, savedenv, permitted):
     """Inherit variables from the initial environment."""
     exportlist = bb.utils.preserved_envvars_exported()
     for s in savedenv.keys():
-        try:
-            setVar(s, getVar(s, savedenv, True), d)
-            if s in exportlist:
-                setVarFlag(s, "export", True, d)
-        except TypeError:
-            pass
+        if s in permitted:
+            try:
+                setVar(s, getVar(s, savedenv, True), d)
+                if s in exportlist:
+                    setVarFlag(s, "export", True, d)
+            except TypeError:
+                pass
 
 def emit_var(var, o=sys.__stdout__, d = init(), all=False):
     """Emit a variable to be sourced by a shell."""
diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index 4eac285..a9c56e9 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -565,18 +565,27 @@ def create_interactive_env(d):
     for k in preserved_envvars_exported_interactive():
         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():
     """
     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_ENV_WHITELIST' in os.environ:
-            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())
+        good_vars = approved_variables()
         filter_environment(good_vars)
 
 def empty_environment():
-- 
1.7.6




^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH 1/1] Ensure only the filtered environment variables are inherited from the OS
  2011-08-13  0:58 ` [RFC PATCH 1/1] Ensure only the filtered environment variables are inherited from the OS Joshua Lock
@ 2011-08-15  8:41   ` Richard Purdie
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Purdie @ 2011-08-15  8:41 UTC (permalink / raw)
  To: Joshua Lock; +Cc: bitbake-devel

On Fri, 2011-08-12 at 17:58 -0700, Joshua Lock wrote:
> 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>
> Signed-off-by: Joshua Lock <josh@linux.intel.com>
> ---
>  bin/bitbake-layers |    6 +++---
>  lib/bb/cooker.py   |    3 ++-
>  lib/bb/data.py     |   15 ++++++++-------
>  lib/bb/utils.py    |   23 ++++++++++++++++-------
>  4 files changed, 29 insertions(+), 18 deletions(-)

Merged to master, thanks.

Richard






^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-08-15  8:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-13  0:58 [RFC PATCH 0/1] Don't include cleaned variables in inherited environment Joshua Lock
2011-08-13  0:58 ` [RFC PATCH 1/1] Ensure only the filtered environment variables are inherited from the OS Joshua Lock
2011-08-15  8:41   ` Richard Purdie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox