All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] data: Avoid attempting to assign readonly shell vars
@ 2014-12-18  1:11 Richard Tollerton
  2014-12-18  1:11 ` [PATCH] data: escape '$' in shell variable assignment Richard Tollerton
  2014-12-18 10:29 ` [PATCH] data: Avoid attempting to assign readonly shell vars Richard Purdie
  0 siblings, 2 replies; 7+ messages in thread
From: Richard Tollerton @ 2014-12-18  1:11 UTC (permalink / raw)
  To: bitbake-devel

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@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



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

end of thread, other threads:[~2014-12-19  0:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-18  1:11 [PATCH] data: Avoid attempting to assign readonly shell vars Richard Tollerton
2014-12-18  1:11 ` [PATCH] data: escape '$' in shell variable assignment Richard Tollerton
2014-12-18 10:29 ` [PATCH] data: Avoid attempting to assign readonly shell vars Richard Purdie
2014-12-18 20:18   ` Richard Tollerton
2014-12-18 22:28     ` Richard Purdie
2014-12-18 23:47       ` Richard Tollerton
2014-12-19  0:03         ` Richard Tollerton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.