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

Commit 3f241026 authored by Tom Marshall's avatar Tom Marshall Committed by Michael Bestas
Browse files

adb: Look for executables in alternate places

 * Restore global variable recovery_mode.  This is set based on the
   commandline parameter --banner.

 * Use /sbin for path to 'sh' and 'bu' when in recovery mode.

 * Honor persist.sys.adb.shell when not in recovery mode.

Change-Id: I02ac651397021097fe865436c982e2b720d7917f
parent e9fea94c
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -201,6 +201,10 @@ int local_connect_arbitrary_ports(int console_port, int adb_port, std::string*

ConnectionState connection_state(atransport *t);

#if !ADB_HOST
extern int recovery_mode;
#endif

extern const char* adb_device_banner;

#if !ADB_HOST
+4 −0
Original line number Diff line number Diff line
@@ -211,6 +211,8 @@ int adbd_main(int server_port) {
    return 0;
}

int recovery_mode = 0;

int main(int argc, char** argv) {
    while (true) {
        static struct option opts[] = {
@@ -242,6 +244,8 @@ int main(int argc, char** argv) {
        }
    }

    recovery_mode = (strcmp(adb_device_banner, "recovery") == 0);

    close_stdin();

    debuggerd_init(nullptr);
+12 −3
Original line number Diff line number Diff line
@@ -267,6 +267,13 @@ static int create_service_thread(const char* service_name, void (*func)(int, voi
    return s[0];
}

#if !ADB_HOST
static const char* bu_path()
{
    return (recovery_mode ? "/sbin/bu" : "/system/bin/bu");
}
#endif

int service_to_fd(const char* name, const atransport* transport) {
    int ret = -1;

@@ -300,12 +307,14 @@ int service_to_fd(const char* name, const atransport* transport) {
    } else if(!strncmp(name, "unroot:", 7)) {
        ret = create_service_thread("unroot", restart_unroot_service, nullptr);
    } else if(!strncmp(name, "backup:", 7)) {
        ret = StartSubprocess(android::base::StringPrintf("/system/bin/bu backup %s",
        ret = StartSubprocess(android::base::StringPrintf("%s backup %s",
                                                          bu_path(),
                                                          (name + 7)).c_str(),
                              nullptr, SubprocessType::kRaw, SubprocessProtocol::kNone);
    } else if(!strncmp(name, "restore:", 8)) {
        ret = StartSubprocess("/system/bin/bu restore", nullptr, SubprocessType::kRaw,
                              SubprocessProtocol::kNone);
        ret = StartSubprocess(android::base::StringPrintf("%s restore",
                                                         bu_path()).c_str(),
                              nullptr, SubprocessType::kRaw, SubprocessProtocol::kNone);
    } else if(!strncmp(name, "tcpip:", 6)) {
        int port;
        if (sscanf(name + 6, "%d", &port) != 1) {
+25 −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>
@@ -105,8 +106,26 @@
#include "adb_utils.h"
#include "security_log_tags.h"

#include "cutils/properties.h"

namespace {

static std::string get_sh_path()
{
    if (recovery_mode) {
        return "/sbin/sh";
    }

    char propbuf[PROPERTY_VALUE_MAX];
    struct stat st;

    property_get("persist.sys.adb.shell", propbuf, "");
    if (propbuf[0] && stat(propbuf, &st) == 0) {
        return propbuf;
    }
    return _PATH_BSHELL;
}

// Reads from |fd| until close or failure.
std::string ReadAll(int fd) {
    char buffer[512];
@@ -325,12 +344,15 @@ bool Subprocess::ForkAndExec(std::string* error) {
        // processes, so we need to manually reset back to SIG_DFL here (http://b/35209888).
        signal(SIGPIPE, SIG_DFL);

        std::string sh_path = get_sh_path();

        if (command_.empty()) {
            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: ");
        std::string errmsg = "exec '" + sh_path + "' failed: ";
        WriteFdExactly(child_error_sfd, errmsg.c_str());
        WriteFdExactly(child_error_sfd, strerror(errno));
        child_error_sfd.reset(-1);
        _Exit(1);
+2 −0
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@
#include "adb_io.h"
#include "sysdeps.h"

int recovery_mode = 0;

class ShellServiceTest : public ::testing::Test {
  public:
    static void SetUpTestCase() {