Fix ensure_bb implementation

Close #2549, close #2560
This commit is contained in:
topjohnwu 2020-03-19 03:48:23 -07:00
parent 47e50e8511
commit ed7e560849

View File

@ -86,23 +86,40 @@ setup_flashable() {
}
ensure_bb() {
[ -o standalone ] && return
set -o standalone 2>/dev/null && return
if set -o | grep -q standalone; then
# We are definitely in busybox ash
set -o standalone
return
fi
# At this point, we are not running in BusyBox ash
# Find our busybox binary
local BUSYBOX
local bb
if [ -f $TMPDIR/busybox ]; then
BUSYBOX=$TMPDIR/busybox
bb=$TMPDIR/busybox
elif [ -f $MAGISKBIN/busybox ]; then
BUSYBOX=$MAGISKBIN/busybox
bb=$MAGISKBIN/busybox
else
abort "! Cannot find BusyBox"
fi
chmod 755 $bb
# Find our current arguments
# Run in busybox environment to ensure consistent results
# /proc/<pid>/cmdline shall be <interpreter> <script> <arguments...>
local cmds=$($bb sh -o standalone -c "
tr '\0' '\n' < /proc/$$/cmdline | (while read -r arg; do
if [ -z \"\$cmds\" ]; then
# Skip the first argument as we want to change the interpreter
cmds=\"sh -o standalone\"
else
cmds=\"\$cmds '\$arg'\"
fi
done
echo \$cmds)")
# Re-exec our script
chmod 755 $BUSYBOX
exec $BUSYBOX sh -o standalone $0 "$@"
echo $cmds | $bb xargs $bb
exit
}
recovery_actions() {