diff options
| author | Jayant Chowdhary <jchowdhary@google.com> | 2017-09-01 16:29:44 -0700 |
|---|---|---|
| committer | Jayant Chowdhary <jchowdhary@google.com> | 2017-09-07 17:19:21 -0700 |
| commit | ab2f79c0daa113ceaacaa59c4573ba606ab7de15 (patch) | |
| tree | 47b2c3045044274ff6a1413f106ed96cb4e8874c /libc/bionic/__bionic_get_shell_path.cpp | |
| parent | 04503da174b5e51ba9035fb79521a6a2af17c111 (diff) | |
For devices which are not treble enabled, return the system shell.
For treble enabled devices, still return the appropriate shell depending
on whether the process is a vendor process or a system one.
Test: Manual testing: on a bullhead device, ran test programs from
/vendor/bin which used popen() and system(). The calls succeeded.
Bug: 65054230
Bug: 64516799
Merged-In: I15dfdbb107cfca7c0f92f337c9bb46b9876eb38e
Change-Id: I15dfdbb107cfca7c0f92f337c9bb46b9876eb38e
(cherry picked from commit 1e52871773505edf70d10a3af7b003e9320ef6a3)
Diffstat (limited to 'libc/bionic/__bionic_get_shell_path.cpp')
| -rw-r--r-- | libc/bionic/__bionic_get_shell_path.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/libc/bionic/__bionic_get_shell_path.cpp b/libc/bionic/__bionic_get_shell_path.cpp index 477fa4a1b..41162e93e 100644 --- a/libc/bionic/__bionic_get_shell_path.cpp +++ b/libc/bionic/__bionic_get_shell_path.cpp @@ -31,18 +31,24 @@ #include <sys/cdefs.h> #include <unistd.h> -__LIBC_HIDDEN__ static const char* __libc_system_sh = "/system/bin/sh"; -__LIBC_HIDDEN__ static const char* __libc_vendor_sh = "/vendor/bin/sh"; +#define VENDOR_PREFIX "/vendor/" static const char* init_sh_path() { + /* 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 + * in $PATH for the vendor shell, simply return the system shell. + */ + +#ifdef __ANDROID_TREBLE__ /* look for /system or /vendor prefix */ - char exe_path[7]; + char exe_path[strlen(VENDOR_PREFIX)]; ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path)); - if (len != -1 && !strncmp(exe_path, __libc_vendor_sh, sizeof(exe_path))) { - return __libc_vendor_sh; + if (len != -1 && !strncmp(exe_path, VENDOR_PREFIX, strlen(VENDOR_PREFIX))) { + return "/vendor/bin/sh"; } - - return __libc_system_sh; +#endif + return "/system/bin/sh"; } __LIBC_HIDDEN__ extern "C" const char* __bionic_get_shell_path() { |
