aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Marshall <tdm.code@gmail.com>2019-01-10 16:18:59 -0800
committermosimchah <mosimchah@gmail.com>2019-04-17 07:50:42 -0400
commit9dd5b845b79ed79b170e23d1590ccc1e24364a6a (patch)
treee8200433e6339b748c51c9cee181e5cd24d84d00
parent85ba804f356926145c9c3420c3fd08d4bc078b4a (diff)
bionic: Prefer /sbin/sh if it existso8.1
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.cpp7
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 41162e93e..20bd7605f 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