Android O system function fails to execute the reboot command

Recently, there is a bug in Android O fastmmi tossing: in the restart options, select "shut down", the machine does not perform the shutdown operation

The analysis process is as follows:

LINUX/android/vendor/qcom/proprietary/fastmmi/mmi/func_map.cpp


It is found that in the process_reboot() function, system("reboot -p") is indeed executed, but through the WEXITSTATUS tracking code, it is found that the execution of this command fails (because its return value is 127)


However, it is found that if you use system ("/system/bin/reboot -p"), the shutdown operation can be performed normally, and the system() function returns 0

And if you use your own odm_system ("reboot -p") implemented according to its principle, it can also be executed successfully, and the machine will be shut down. Note: /system/bin/sh is used.


I also found that if you replace the reboot with other commands, such as the ls command (the command that exists in the /vendor/bin/ directory), system ("ls") can also be executed normally, which is very confusing for a while.

So I found the source code of the system function with curiosity

LINUX/android/bionic/libc/upstream-openbsd/lib/libc/stdlib/system.c


Through the async_safe_format_log() tracking code, it is found that the value of the _PATH_BSHELL variable is actually /vendor/bin/sh, not /system/bin/sh as I originally thought, tracking this macro definition found


Due to the introduction of a new partition vendor by Android O Qualcomm, the value of the _PATH_BSHELL variable is /vendor/bin/sh instead of /system/bin/sh, but the executable program reboot does not exist in the /vendor/bin/ directory, reboot The executable program only exists in the /system/bin directory, so the system() function fails to execute.

A small episode : the shell entered by adb shell is /system/bin/sh, which can be viewed through the env command


So using adb shell reboot -p can also perform shutdown operations normally.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324417593&siteId=291194637