Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b99b9cac authored by Tom Marshall's avatar Tom Marshall Committed by Bruno Martins
Browse files

adb: Look for shell executable in alternate places

 * Honor persist.sys.adb.shell.

Change-Id: I02ac651397021097fe865436c982e2b720d7917f
parent 8972dc26
Loading
Loading
Loading
Loading
+18 −3
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@
#include <pty.h>
#include <pwd.h>
#include <sys/select.h>
#include <sys/stat.h>
#include <termios.h>

#include <memory>
@@ -113,6 +114,17 @@

namespace {

static std::string GetShellPath() {
    std::string shell = android::base::GetProperty("persist.sys.adb.shell", "");
    struct stat st;

    if (!shell.empty() && stat(shell.c_str(), &st) != -1) {
        return shell;
    }

    return _PATH_BSHELL;
}

// Reads from |fd| until close or failure.
std::string ReadAll(int fd) {
    char buffer[512];
@@ -360,13 +372,16 @@ bool Subprocess::ForkAndExec(std::string* error) {
        }
#endif

        std::string sh_path = GetShellPath();

        if (command_.empty()) {
            // Spawn a login shell if we don't have a command.
            execle(_PATH_BSHELL, "-" _PATH_BSHELL, nullptr, cenv.data());
            execle(sh_path.c_str(), sh_path.c_str(), "-", nullptr, cenv.data());
        } else {
            execle(_PATH_BSHELL, _PATH_BSHELL, "-c", command_.c_str(), nullptr, cenv.data());
            execle(sh_path.c_str(), sh_path.c_str(), "-c", command_.c_str(), nullptr, cenv.data());
        }
        WriteFdExactly(child_error_sfd, "exec '" _PATH_BSHELL "' failed: ");
        WriteFdExactly(child_error_sfd,
                       android::base::StringPrintf("Exec '%s' failed: ", sh_path.c_str()).c_str());
        WriteFdExactly(child_error_sfd, strerror(errno));
        child_error_sfd.reset(-1);
        _Exit(1);