Skip to content

Commit ed7e560

Browse files
committed
Fix ensure_bb implementation
Close #2549, close #2560
1 parent 47e50e8 commit ed7e560

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

scripts/util_functions.sh

+25-8
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,40 @@ setup_flashable() {
8686
}
8787

8888
ensure_bb() {
89-
[ -o standalone ] && return
90-
set -o standalone 2>/dev/null && return
89+
if set -o | grep -q standalone; then
90+
# We are definitely in busybox ash
91+
set -o standalone
92+
return
93+
fi
9194

92-
# At this point, we are not running in BusyBox ash
9395
# Find our busybox binary
94-
local BUSYBOX
96+
local bb
9597
if [ -f $TMPDIR/busybox ]; then
96-
BUSYBOX=$TMPDIR/busybox
98+
bb=$TMPDIR/busybox
9799
elif [ -f $MAGISKBIN/busybox ]; then
98-
BUSYBOX=$MAGISKBIN/busybox
100+
bb=$MAGISKBIN/busybox
99101
else
100102
abort "! Cannot find BusyBox"
101103
fi
104+
chmod 755 $bb
105+
106+
# Find our current arguments
107+
# Run in busybox environment to ensure consistent results
108+
# /proc/<pid>/cmdline shall be <interpreter> <script> <arguments...>
109+
local cmds=$($bb sh -o standalone -c "
110+
tr '\0' '\n' < /proc/$$/cmdline | (while read -r arg; do
111+
if [ -z \"\$cmds\" ]; then
112+
# Skip the first argument as we want to change the interpreter
113+
cmds=\"sh -o standalone\"
114+
else
115+
cmds=\"\$cmds '\$arg'\"
116+
fi
117+
done
118+
echo \$cmds)")
102119

103120
# Re-exec our script
104-
chmod 755 $BUSYBOX
105-
exec $BUSYBOX sh -o standalone $0 "$@"
121+
echo $cmds | $bb xargs $bb
122+
exit
106123
}
107124

108125
recovery_actions() {

0 commit comments

Comments
 (0)