__bionic_get_shell_path(): "just work" on the host.

This lets you run _device_ unit tests on the host without setting up
a /system (as run-test.sh does). Before this, isolated gtests just
silently fail.

I initially didn't like the idea of adding an extra system call here,
for fear of breaking seccomp jails ... but then reasoned that if you're
about to shell out (which is the only time this is used: popen(),
system(), execvpe()), you're unlikely to be in a seccomp jail!

Change-Id: I5924daacbfab6524d826355adad5a88bdc11161f
diff --git a/libc/bionic/__bionic_get_shell_path.cpp b/libc/bionic/__bionic_get_shell_path.cpp
index 3ea256d..de79325 100644
--- a/libc/bionic/__bionic_get_shell_path.cpp
+++ b/libc/bionic/__bionic_get_shell_path.cpp
@@ -28,15 +28,15 @@
 
 #include "private/__bionic_get_shell_path.h"
 
+#include <unistd.h>
+
 const char* __bionic_get_shell_path() {
-  // For the host Bionic, we use the standard /bin/sh.
-  // Since P there's a /bin -> /system/bin symlink that means this will work
-  // for the device too, but as long as the NDK supports earlier API levels,
-  // we should probably make sure that this works in static binaries run on
-  // those OS versions too.
-#if !defined(__ANDROID__)
-  return "/bin/sh";
-#else
-  return "/system/bin/sh";
-#endif
+  // Since API level 28 there's a /bin -> /system/bin symlink that means
+  // /bin/sh will work for the device too, but as long as the NDK supports
+  // earlier API levels, falling back to /system/bin/sh ensures that static
+  // binaries run on those OS versions too.
+  // This whole function can be removed and replaced by hard-coded /bin/sh
+  // when we no longer support anything below API level 28.
+  static bool have_bin_sh = !access("/bin/sh", F_OK);
+  return have_bin_sh ? "/bin/sh" : "/system/bin/sh";
 }