aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2017-09-12 18:08:42 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2017-09-12 18:08:42 +0000
commit4785edf0a469883a7e3c6bb4bcdbb9b843c969f6 (patch)
tree855119ea7d00c309146c6c46b811ff6e70531e55
parent17929be412cfb0d8c85c110cb2dd9f06c9c6feab (diff)
parentb04bdacb98df330debf4b64fd99264028205bc4b (diff)
downloadbionic-4785edf0a469883a7e3c6bb4bcdbb9b843c969f6.tar.gz
release-request-dabd8cf7-7af2-48e9-a296-ccc6a71cc25d-for-git_oc-m2-release-4328410 snap-temp-L55300000101694322
Change-Id: Ic001ccd227b39f08b7a4edac224a3f0025b895b4
-rw-r--r--libc/Android.bp6
-rw-r--r--libc/bionic/__bionic_get_shell_path.cpp20
2 files changed, 18 insertions, 8 deletions
diff --git a/libc/Android.bp b/libc/Android.bp
index b5229cbbf..a0d1f237c 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -1509,7 +1509,11 @@ cc_library_static {
srcs: ["bionic/mmap.cpp"],
},
},
-
+ product_variables: {
+ treble: {
+ cflags: ["-D__ANDROID_TREBLE__"],
+ },
+ },
cppflags: ["-Wold-style-cast"],
local_include_dirs: ["stdio"],
include_dirs: ["bionic/libstdc++/include"],
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() {