summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-03-21 21:11:41 -0700
committerElliott Hughes <enh@google.com>2019-03-25 17:28:22 -0700
commit886370c2402e6fcf6ac613a8603f99fff66cd20c (patch)
tree55973f92a11704c20bc09aa8a74c2094c7b1c2a7 /libc
parentebdf4c19f9e034d7ec8e0e57539890d5c93eaed1 (diff)
Fix internal uses of _PATH_BSHELL.
We regressed on this recently: code under the upstream-* directories has _PATH_BSHELL defined as a call to __bionic_get_shell_path(). In our own code, we may as well just call it directly. Bug: https://issuetracker.google.com/129030706 Test: ran tests Change-Id: Ic2423f521272be95e67f94771772fe8072636ef0
Diffstat (limited to 'libc')
-rw-r--r--libc/bionic/__bionic_get_shell_path.cpp4
-rw-r--r--libc/bionic/exec.cpp3
-rw-r--r--libc/bionic/system.cpp4
-rw-r--r--libc/private/__bionic_get_shell_path.h31
-rw-r--r--libc/stdio/stdio.cpp3
5 files changed, 40 insertions, 5 deletions
diff --git a/libc/bionic/__bionic_get_shell_path.cpp b/libc/bionic/__bionic_get_shell_path.cpp
index 135281578..7aeed182e 100644
--- a/libc/bionic/__bionic_get_shell_path.cpp
+++ b/libc/bionic/__bionic_get_shell_path.cpp
@@ -26,6 +26,8 @@
* SUCH DAMAGE.
*/
+#include "private/__bionic_get_shell_path.h"
+
#include <errno.h>
#include <string.h>
#include <sys/cdefs.h>
@@ -51,7 +53,7 @@ static const char* init_sh_path() {
return "/system/bin/sh";
}
-__LIBC_HIDDEN__ extern "C" const char* __bionic_get_shell_path() {
+const char* __bionic_get_shell_path() {
static const char* sh_path = init_sh_path();
return sh_path;
}
diff --git a/libc/bionic/exec.cpp b/libc/bionic/exec.cpp
index 1cf3a589f..3309585d5 100644
--- a/libc/bionic/exec.cpp
+++ b/libc/bionic/exec.cpp
@@ -39,6 +39,7 @@
#include <string.h>
#include <unistd.h>
+#include "private/__bionic_get_shell_path.h"
#include "private/FdPath.h"
extern "C" char** environ;
@@ -111,7 +112,7 @@ static int __exec_as_script(const char* buf, char* const* argv, char* const* env
script_argv[0] = "sh";
script_argv[1] = buf;
memcpy(script_argv + 2, argv + 1, arg_count * sizeof(char*));
- return execve(_PATH_BSHELL, const_cast<char**>(script_argv), envp);
+ return execve(__bionic_get_shell_path(), const_cast<char**>(script_argv), envp);
}
int execvpe(const char* name, char* const* argv, char* const* envp) {
diff --git a/libc/bionic/system.cpp b/libc/bionic/system.cpp
index 7411ae529..950f05c7d 100644
--- a/libc/bionic/system.cpp
+++ b/libc/bionic/system.cpp
@@ -27,12 +27,12 @@
*/
#include <errno.h>
-#include <paths.h>
#include <stdlib.h>
#include <spawn.h>
#include <sys/wait.h>
#include <unistd.h>
+#include "private/__bionic_get_shell_path.h"
#include "private/ScopedSignalBlocker.h"
#include "private/ScopedSignalHandler.h"
@@ -58,7 +58,7 @@ int system(const char* command) {
const char* argv[] = { "sh", "-c", command, nullptr };
pid_t child;
- if ((errno = posix_spawn(&child, _PATH_BSHELL, nullptr, &attributes,
+ if ((errno = posix_spawn(&child, __bionic_get_shell_path(), nullptr, &attributes,
const_cast<char**>(argv), environ)) != 0) {
return -1;
}
diff --git a/libc/private/__bionic_get_shell_path.h b/libc/private/__bionic_get_shell_path.h
new file mode 100644
index 000000000..171c14a58
--- /dev/null
+++ b/libc/private/__bionic_get_shell_path.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#pragma once
+
+extern "C" const char* __bionic_get_shell_path();
diff --git a/libc/stdio/stdio.cpp b/libc/stdio/stdio.cpp
index d7b69dcb5..d482a91c5 100644
--- a/libc/stdio/stdio.cpp
+++ b/libc/stdio/stdio.cpp
@@ -52,6 +52,7 @@
#include "local.h"
#include "glue.h"
+#include "private/__bionic_get_shell_path.h"
#include "private/bionic_fortify.h"
#include "private/ErrnoRestorer.h"
#include "private/thread_private.h"
@@ -1226,7 +1227,7 @@ FILE* popen(const char* cmd, const char* mode) {
if (dup2(fds[child], desired_child_fd) == -1) _exit(127);
close(fds[child]);
if (bidirectional) dup2(STDOUT_FILENO, STDIN_FILENO);
- execl(_PATH_BSHELL, "sh", "-c", cmd, nullptr);
+ execl(__bionic_get_shell_path(), "sh", "-c", cmd, nullptr);
_exit(127);
}