Skip to contentSkip to conversation

Avoid use of "export -n"

PATCH In review Daniel Drake 2 participants 2 messages Mar 16, 2012 – Mar 21, 2012 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Avoid use of "export -n"

"export -n" is a bash extension, not part of POSIX, and is hence incompatible with the busybox shell.

This was breaking boot when the busybox module was used.

Reimplement the scope change in a few lines of standard shell code.

---
 modules.d/99base/init.sh |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
modules.d/99base/init.sh +8 -1
index 5d51c9d..f599fae 100755
@@ -263,8 +263,15 @@ else
     udevadm info --cleanup-db
 fi
 
+# Retain the values of these variables but ensure that they are unexported
+# This is a POSIX-compliant equivalent of bash's "export -n"
+for var in root rflags fstype netroot NEWROOT; do
+    eval tmp=\$$var
+    unset $var
+    [ -n "$tmp" ] && eval $var=\"$tmp\"
+done
+
 export RD_TIMESTAMP
-export -n root rflags fstype netroot NEWROOT
 set +x # Turn off debugging for this section
 # Clean up the environment
 for i in $(export -p); do
Signature · 1 line
1.7.7.6

A message that is not in the archive (sent off-list or not yet received): 20120316211124.8FFC69D401E-k/[email protected]

#2 lore raw

Am 16.03.2012 22:11, schrieb Daniel Drake:

Quoted 21 lines

"export -n" is a bash extension, not part of POSIX, and is hence incompatible with the busybox shell.

This was breaking boot when the busybox module was used.

Reimplement the scope change in a few lines of standard shell code.

---
 modules.d/99base/init.sh |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
modules.d/99base/init.sh +3 -0
index 5d51c9d..f599fae 100755
@@ -263,8 +263,15 @@ else
     udevadm info --cleanup-db
 fi
 
+# Retain the values of these variables but ensure that they are unexported
+# This is a POSIX-compliant equivalent of bash's "export -n"
+for var in root rflags fstype netroot NEWROOT; do

modules.d/99base/init.sh else · line 277

Quoted 10 lines
modules.d/99base/init.sh +5 -1
+    eval tmp=\$$var
+    unset $var
+    [ -n "$tmp" ] && eval $var=\"$tmp\"
+done
+
 export RD_TIMESTAMP
-export -n root rflags fstype netroot NEWROOT
 set +x # Turn off debugging for this section
 # Clean up the environment
 for i in $(export -p); do

pushed