summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2012-12-22 19:10:01 +0100
committerDave Reisner <dreisner@archlinux.org>2013-01-12 22:59:33 +0100
commit13f455b2a194f9bfa3d4584a8a24e941d55fb271 (patch)
tree760bf09a47f66adf8069e5237c9bcfbe7e237718
parent823e2454176d4381cd3acc30481e9d84cdc298b1 (diff)
downloadmkinitcpio-13f455b2a194f9bfa3d4584a8a24e941d55fb271.tar.gz
mkinitcpio-13f455b2a194f9bfa3d4584a8a24e941d55fb271.tar.xz
init_functions: namespace parsed vars from cmdline
It's possible, though unlikely, that someone expecting a variable of the name, e.g. "rhs" or "lhs" to be propagated from the kernel cmdline could be sadly let down because of the local scoping. Give our localized vars names less likely to clash. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
-rw-r--r--init_functions46
1 files changed, 23 insertions, 23 deletions
diff --git a/init_functions b/init_functions
index 761f7a2..ff6a3b4 100644
--- a/init_functions
+++ b/init_functions
@@ -71,49 +71,49 @@ run_hookfunctions() {
}
parse_cmdline() {
- local w in_quotes lhs rhs
- in_quotes=0
- for w in $(cat /proc/cmdline); do
- if [ "$in_quotes" = 0 ]; then
- case "$w" in
+ local _w _quoted _lhs _rhs _cmdline
+ read -r _cmdline </proc/cmdline
+ for _w in $_cmdline; do
+ if [ -z "$_quoted" ]; then
+ case $_w in
# ignore everything after a # in the commandline
\#*) break ;;
# special cases
- rw|ro) rwopt=$w ;;
+ rw|ro) rwopt=$_w ;;
fsck.mode=*)
- case ${w#*=} in
+ case ${_w#*=} in
force) forcefsck=y ;;
skip) fastboot=y ;;
esac
;;
# abide by shell variable naming rules
[[:alpha:]_]*=*)
- rhs=${w#*=}
- lhs=${w%%=*}
- lhs=${lhs//[-.]/_}
- if [ '"' = "${rhs:0:1}" ]; then
- if [ '"' = "${rhs:$((${#rhs}-1))}" ]; then
- rhs="${rhs:1:$((${#rhs}-2))}"
+ _rhs=${_w#*=}
+ _lhs=${_w%%=*}
+ _lhs=${_lhs//[-.]/_}
+ if [ '"' = "${_rhs:0:1}" ]; then
+ if [ '"' = "${_rhs:$((${#_rhs}-1))}" ]; then
+ _rhs="${_rhs:1:$((${#_rhs}-2))}"
else
- rhs=${rhs:1}
- in_quotes=1
+ _rhs=${_rhs:1}
+ _quoted=1
continue
fi
fi
- eval $lhs=\$rhs
+ eval $_lhs=\$_rhs
;;
[[:alpha:]_]*)
- lhs=${w//[-.]/_}
- eval $lhs=y
+ _lhs=${_w//[-.]/_}
+ eval $_lhs=y
;;
esac
else
- if [ '"' = "${w:$((${#w}-1))}" ]; then
- rhs="$rhs ${w%\"}"
- in_quotes=0
- eval $lhs=\$rhs
+ if [ '"' = "${_w:$((${#_w}-1))}" ]; then
+ _rhs="$_rhs ${_w%\"}"
+ unset _quoted
+ eval $_lhs=\$_rhs
else
- rhs="$rhs $w"
+ _rhs="$_rhs $_w"
fi
fi
done