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 #include #include @@ -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 #include +#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(script_argv), envp); + return execve(__bionic_get_shell_path(), const_cast(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 -#include #include #include #include #include +#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(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 8144e5f1d..dc232002e 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" @@ -1218,7 +1219,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); }