OSDN Git Service

For devices which are not treble enabled, return the system shell.
authorJayant Chowdhary <jchowdhary@google.com>
Fri, 1 Sep 2017 23:29:44 +0000 (16:29 -0700)
committerJayant Chowdhary <jchowdhary@google.com>
Thu, 7 Sep 2017 21:25:50 +0000 (14:25 -0700)
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

Change-Id: I15dfdbb107cfca7c0f92f337c9bb46b9876eb38e

libc/Android.bp
libc/bionic/__bionic_get_shell_path.cpp

index b5229cb..a0d1f23 100644 (file)
@@ -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"],
index 477fa4a..41162e9 100644 (file)
 #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() {