diff options
author | Dave Reisner <dreisner@archlinux.org> | 2011-11-13 20:48:31 +0100 |
---|---|---|
committer | Dave Reisner <dreisner@archlinux.org> | 2011-11-15 04:48:36 +0100 |
commit | 254c99b80f7f5269409b6af61cb90363bd9f66f5 (patch) | |
tree | b3cc8b3bab6a001a5672d74b1524ee15eb5b0234 /init_functions | |
parent | 00eefc36ae7c8f5f893b2c184fd8f32a3629031b (diff) | |
download | mkinitcpio-254c99b80f7f5269409b6af61cb90363bd9f66f5.tar.gz mkinitcpio-254c99b80f7f5269409b6af61cb90363bd9f66f5.tar.xz |
init_functions: simplify parse_cmdline
Do variable name validation via the case labels rather than via PEs.
This frees up the fallthrough case to simply ignore things we don't
understand (and not exist).
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Diffstat (limited to 'init_functions')
-rw-r--r-- | init_functions | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/init_functions b/init_functions index 5ec199e..42e6249 100644 --- a/init_functions +++ b/init_functions @@ -48,43 +48,41 @@ parse_cmdline() { local w in_quotes lhs rhs in_quotes=0 for w in $(cat /proc/cmdline); do - if [ ${in_quotes} -eq 0 ]; then - case "${w}" in - \#*) break ;; # ignore everything after a # in the commandline - # The kernel passes those to init on its own - [0123456Ss]) ;; - single) ;; - rw|ro) rwopt="$w" ;; - # only export stuff that does work with ash :) - =*) ;; - *=*) rhs=${w#*=} + if [ "$in_quotes" = 0 ]; then + case "$w" in + # ignore everything after a # in the commandline + \#*) break ;; + # special cases + rw|ro) rwopt=$w ;; + forcefsck) FORCEFSCK=-f ;; + # abide by shell variable naming rules + [[:alpha:]_]*=*) + rhs=${w#*=} lhs=${w%%=*} lhs=${lhs//[-.]/_} if [ '"' = "${rhs:0:1}" ]; then - if [ "${rhs:$((${#rhs}-1))}" = '"' ]; then + if [ '"' = "${rhs:$((${#rhs}-1))}" ]; then rhs="${rhs:1:$((${#rhs}-2))}" else - rhs="${rhs:1}" + rhs=${rhs:1} in_quotes=1 continue fi fi - [ "$lhs" = "${lhs//[^0-9a-zA-Z]}" ] && [ "$lhs" = "${lhs#[0-9]}" ] && eval ${lhs}=\${rhs} + eval $lhs=\$rhs ;; - forcefsck) - FORCEFSCK="-f" - ;; - *) lhs=${w//[-.]/_} - [ "$lhs" = "${lhs//[^0-9a-zA-Z]}" ] && [ "$lhs" = "${lhs#[0-9]}" ] && eval ${lhs}=y + [[:alpha:]_]*) + lhs=${w//[-.]/_} + eval $lhs=y ;; esac else if [ '"' = "${w:$((${#w}-1))}" ]; then - rhs="${rhs} ${w%\"}" + rhs="$rhs ${w%\"}" in_quotes=0 - [ "$lhs" = "${lhs//[^0-9a-zA-Z]}" ] && [ "$lhs" = "${lhs#[0-9]}" ] && eval ${lhs}=\${rhs} + eval $lhs=\$rhs else - rhs="${rhs} ${w}" + rhs="$rhs $w" fi fi done |