Fix execvp/execvpe behavior with absolute paths and ENOEXEC.

Bug: http://b/31091962
Change-Id: Id0b3d41868f5e3ed1ccf618bfefb46609367bc9a
diff --git a/libc/bionic/exec.cpp b/libc/bionic/exec.cpp
index 354f931..c43eb90 100644
--- a/libc/bionic/exec.cpp
+++ b/libc/bionic/exec.cpp
@@ -115,7 +115,8 @@
 
   // If it's an absolute or relative path name, it's easy.
   if (strchr(name, '/') && execve(name, argv, envp) == -1) {
-    return __exec_as_script(name, argv, envp);
+    if (errno == ENOEXEC) return __exec_as_script(name, argv, envp);
+    return -1;
   }
 
   // Get the path we're searching.
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp
index 69d1906..6299469 100644
--- a/tests/unistd_test.cpp
+++ b/tests/unistd_test.cpp
@@ -1272,3 +1272,12 @@
   // implementation.
   eth.Run([&]() { execvpe(tf.filename, eth.GetArgs(), eth.GetEnv()); }, 0, "script\n");
 }
+
+TEST(UNISTD_TEST, execvp_libcore_test_55017) {
+  ExecTestHelper eth;
+  eth.SetArgs({"/system/bin/does-not-exist", nullptr});
+
+  errno = 0;
+  ASSERT_EQ(-1, execvp("/system/bin/does-not-exist", eth.GetArgs()));
+  ASSERT_EQ(ENOENT, errno);
+}