[bitbake-devel] [PATCH] data: Avoid attempting to assign readonly shell vars

Richard Tollerton rich.tollerton at ni.com
Thu Dec 18 01:11:17 UTC 2014


Attempting to set a read-only shell variable kills the shell. This is
required POSIX behavior, it can't be disabled, and it's implemented by
both dash and bash (although it seems to have only started happening in
bash 4.3 and later, and only when run as /bin/sh).

This breaks `bitbake -c devshell` if bash 4.3 is installed, because
BASHOPTS (and a boatload of other shell variables) are readonly.

The fix is to attempt to modify the variable in a subshell before doing
the assignment.

Signed-off-by: Richard Tollerton <rich.tollerton at ni.com>
---
 lib/bb/data.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/bb/data.py b/lib/bb/data.py
index eb628c7..6c8d644 100644
--- a/lib/bb/data.py
+++ b/lib/bb/data.py
@@ -231,6 +231,10 @@ def emit_var(var, o=sys.__stdout__, d = init(), all=False):
         o.write("%s() {\n%s\n}\n" % (varExpanded, val))
         return 1
 
+    # If the variable is readonly, attempting to set it will KILL THE SCRIPT.
+    # Avoid this by attempting to modify the variable in a subshell.
+    o.write('(unset %s 2>/dev/null) &&' % (varExpanded))
+
     if export:
         o.write('export ')
 
-- 
2.1.3




More information about the bitbake-devel mailing list