Skip to content

Commit

Permalink
fix(99base): adjust to allow mksh as initrd shell
Browse files Browse the repository at this point in the history
Use printf instead of echo in str_replace() to preserve escapes.
Find command paths while PATH includes /usr/sbin. (switch_root was
  not found after the original environment is restored on Fedora.)
  • Loading branch information
FGrose authored and aafeijoo-suse committed Mar 29, 2023
1 parent 8b951d2 commit a0d14d3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion modules.d/99base/dracut-dev-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ str_replace() {
out="${out}${chop}$r"
in="${in#*"$s"}"
done
echo "${out}${in}"
printf -- '%s' "${out}${in}"
}

# get a systemd-compatible unit name from a path
Expand Down
9 changes: 5 additions & 4 deletions modules.d/99base/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ udevadm info --cleanup-db

debug_off # Turn off debugging for this section

CAPSH=$(command -v capsh)
SWITCH_ROOT=$(command -v switch_root)

# unexport some vars
export_n root rflags fstype netroot NEWROOT
unset CMDLINE
Expand Down Expand Up @@ -370,8 +373,6 @@ info "Switching root"

unset PS4

CAPSH=$(command -v capsh)
SWITCH_ROOT=$(command -v switch_root)
PATH=$OLDPATH
export PATH

Expand All @@ -380,10 +381,10 @@ if [ -f /etc/capsdrop ]; then
info "Calling $INIT with capabilities $CAPS_INIT_DROP dropped."
unset RD_DEBUG
exec "$CAPSH" --drop="$CAPS_INIT_DROP" -- \
-c "exec switch_root \"$NEWROOT\" \"$INIT\" $initargs" \
-c "exec \"$SWITCH_ROOT\" \"$NEWROOT\" \"$INIT\" $initargs" \
|| {
warn "Command:"
warn capsh --drop="$CAPS_INIT_DROP" -- -c exec switch_root "$NEWROOT" "$INIT" "$initargs"
warn capsh --drop="$CAPS_INIT_DROP" -- -c exec "$SWITCH_ROOT" "$NEWROOT" "$INIT" "$initargs"
warn "failed."
emergency_shell
}
Expand Down

0 comments on commit a0d14d3

Please sign in to comment.