Fix "can't shift that many" crash with empty /proc/cmdline

If /proc/cmdline is empty (like if root=... is set in /etc/cmdline),
modules.d/99base/init will crash with a message saying "can't shift that
many" right before switch_root. The problem is in the block of code that
tries to look for init args. It does something like:

read CMDLINE </proc/cmdline
    [...]
    set $CMDLINE
    shift

If CMDLINE="" then "set $CMDLINE" will dump all the variables to stdout.
(That should be "set -- $CMDLINE" instead.) Since there's no $1, the
"shift" causes an error, and dracut crashes.

The 'shift' was copy-and-pasted from the previous block. It doesn't
belong here; remove it.

[Harald Hoyer <harald@redhat.com>: corrected commit message]
[Harald Hoyer <harald@redhat.com>: fixed indention]

Signed-off-by: Will Woods <wwoods@redhat.com>
master
Will Woods 2011-05-16 19:17:57 -04:00 committed by Harald Hoyer
parent 6787b8ccee
commit 7573ac58f2
1 changed files with 9 additions and 10 deletions

View File

@ -361,19 +361,18 @@ if getarg init= >/dev/null ; then
ignoreargs="console BOOT_IMAGE" ignoreargs="console BOOT_IMAGE"
# only pass arguments after init= to the init # only pass arguments after init= to the init
CLINE=${CLINE#*init=} CLINE=${CLINE#*init=}
set $CLINE set -- $CLINE
shift shift # clear out the rest of the "init=" arg
for x in "$@"; do for x in "$@"; do
for s in $ignoreargs; do for s in $ignoreargs; do
[ "${x%%=*}" = $s ] && continue 2 [ "${x%%=*}" = $s ] && continue 2
done
initargs="$initargs $x"
done done
unset CLINE initargs="$initargs $x"
done
unset CLINE
else else
set +x # Turn off debugging for this section set +x # Turn off debugging for this section
set $CLINE set -- $CLINE
shift
for x in "$@"; do for x in "$@"; do
case "$x" in case "$x" in
[0-9]|s|S|single|emergency|auto ) \ [0-9]|s|S|single|emergency|auto ) \