diff options
| author | Tom Marshall <tdm.code@gmail.com> | 2019-01-10 16:18:59 -0800 |
|---|---|---|
| committer | doc HD <doc.divxm@gmail.com> | 2019-08-02 00:53:06 +0300 |
| commit | 8c2fb0dd2ff737964ad641a333338205dd5e4400 (patch) | |
| tree | 183fbabfb6d4e0451e5c7a2cc39afb75db09acb6 | |
| parent | 64c5e1841567b3903b70d7e7e849119609da71b1 (diff) | |
bionic: Prefer /sbin/sh if it existsp9.0
Prefer /sbin/sh because in recovery (or generally, not booted to the
main Android system), the system shell and its associated rc file
should not be used. One reason is that TMPDIR is set to a path that
will likely not be mounted (/data/local/tmp).
Change-Id: I3ec22aa2537a7795baae6e782134d3b05f4b3ace
| -rw-r--r-- | libc/bionic/__bionic_get_shell_path.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/libc/bionic/__bionic_get_shell_path.cpp b/libc/bionic/__bionic_get_shell_path.cpp index 135281578..2bd49774e 100644 --- a/libc/bionic/__bionic_get_shell_path.cpp +++ b/libc/bionic/__bionic_get_shell_path.cpp @@ -29,11 +29,18 @@ #include <errno.h> #include <string.h> #include <sys/cdefs.h> +#include <sys/stat.h> #include <unistd.h> #define VENDOR_PREFIX "/vendor/" static const char* init_sh_path() { + /* Prefer /sbin/sh */ + struct stat st; + if (stat("/sbin/sh", &st) == 0) { + return "/sbin/sh"; + } + /* If the device is not treble enabled, return the path to the system shell. * Vendor code, on non-treble enabled devices could use system() / popen() * with relative paths for executables on /system. Since /system will not be |
