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

Commit ab6b6e2c authored by Tom Cherry's avatar Tom Cherry Committed by android-build-merger
Browse files

Merge changes I316c13e3,I4d99744d,Id9614b72,I7c98a0b7 am: a78b5b30

am: e0db940e

Change-Id: Id1e2523bf9a1d4719fdbd98c764ee4ae60ce2052
parents 3f89e4ac e0db940e
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -91,14 +91,25 @@ void Action::ExecuteCommand(const Command& command) const {
    auto result = command.InvokeFunc();
    auto duration = t.duration();

    // There are many legacy paths in rootdir/init.rc that will virtually never exist on a new
    // device, such as '/sys/class/leds/jogball-backlight/brightness'.  As of this writing, there
    // are 198 such failures on bullhead.  Instead of spamming the log reporting them, we do not
    // report such failures unless we're running at the DEBUG log level.
    bool report_failure = !result.has_value();
    if (report_failure && android::base::GetMinimumLogSeverity() > android::base::DEBUG &&
        result.error_errno() == ENOENT) {
        report_failure = false;
    }

    // Any action longer than 50ms will be warned to user as slow operation
    if (duration > 50ms || android::base::GetMinimumLogSeverity() <= android::base::DEBUG) {
    if (report_failure || duration > 50ms ||
        android::base::GetMinimumLogSeverity() <= android::base::DEBUG) {
        std::string trigger_name = BuildTriggersString();
        std::string cmd_str = command.BuildCommandString();

        LOG(INFO) << "Command '" << cmd_str << "' action=" << trigger_name << " (" << filename_
                  << ":" << command.line() << ") took " << duration.count() << "ms and "
                  << (result ? "succeeded" : "failed: " + result.error());
                  << (result ? "succeeded" : "failed: " + result.error_string());
    }
}

+17 −8
Original line number Diff line number Diff line
@@ -127,7 +127,9 @@ static Result<Success> do_enable(const std::vector<std::string>& args) {
    Service* svc = ServiceList::GetInstance().FindService(args[1]);
    if (!svc) return Error() << "Could not find service";

    if (!svc->Enable()) return Error() << "Could not enable service";
    if (auto result = svc->Enable(); !result) {
        return Error() << "Could not enable service: " << result.error();
    }

    return Success();
}
@@ -137,8 +139,8 @@ static Result<Success> do_exec(const std::vector<std::string>& args) {
    if (!service) {
        return Error() << "Could not create exec service";
    }
    if (!service->ExecStart()) {
        return Error() << "Could not start exec service";
    if (auto result = service->ExecStart(); !result) {
        return Error() << "Could not start exec service: " << result.error();
    }

    ServiceList::GetInstance().AddService(std::move(service));
@@ -151,16 +153,16 @@ static Result<Success> do_exec_start(const std::vector<std::string>& args) {
        return Error() << "Service not found";
    }

    if (!service->ExecStart()) {
        return Error() << "Could not start Service";
    if (auto result = service->ExecStart(); !result) {
        return Error() << "Could not start exec service: " << result.error();
    }

    return Success();
}

static Result<Success> do_export(const std::vector<std::string>& args) {
    if (!add_environment(args[1].c_str(), args[2].c_str())) {
        return Error();
    if (setenv(args[1].c_str(), args[2].c_str(), 1) == -1) {
        return ErrnoError() << "setenv() failed";
    }
    return Success();
}
@@ -602,7 +604,9 @@ static Result<Success> do_setrlimit(const std::vector<std::string>& args) {
static Result<Success> do_start(const std::vector<std::string>& args) {
    Service* svc = ServiceList::GetInstance().FindService(args[1]);
    if (!svc) return Error() << "service " << args[1] << " not found";
    if (!svc->Start()) return Error() << "failed to start service";
    if (auto result = svc->Start(); !result) {
        return Error() << "Could not start service: " << result.error();
    }
    return Success();
}

@@ -627,6 +631,11 @@ static Result<Success> do_trigger(const std::vector<std::string>& args) {

static Result<Success> do_symlink(const std::vector<std::string>& args) {
    if (symlink(args[1].c_str(), args[2].c_str()) < 0) {
        // The symlink builtin is often used to create symlinks for older devices to be backwards
        // compatible with new paths, therefore we skip reporting this error.
        if (errno == EEXIST && android::base::GetMinimumLogSeverity() > android::base::DEBUG) {
            return Success();
        }
        return ErrnoError() << "symlink() failed";
    }
    return Success();
+1 −2
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@
#include <cutils/android_get_control_file.h>
#include <cutils/sockets.h>

#include "init.h"
#include "util.h"

namespace android {
@@ -62,7 +61,7 @@ void DescriptorInfo::CreateAndPublish(const std::string& globalContext) const {
                [] (char& c) { c = isalnum(c) ? c : '_'; });

  std::string val = std::to_string(fd);
  add_environment(publishedName.c_str(), val.c_str());
  setenv(publishedName.c_str(), val.c_str(), 1);

  // make sure we don't close on exec
  fcntl(fd, F_SETFD, 0);
+2 −36
Original line number Diff line number Diff line
@@ -71,8 +71,6 @@ static char qemu[32];

std::string default_console = "/dev/console";

const char *ENV[32];

static int epoll_fd = -1;

static std::unique_ptr<Timer> waiting_for_prop(nullptr);
@@ -126,38 +124,6 @@ void register_epoll_handler(int fd, void (*fn)()) {
    }
}

/* add_environment - add "key=value" to the current environment */
int add_environment(const char *key, const char *val)
{
    size_t n;
    size_t key_len = strlen(key);

    /* The last environment entry is reserved to terminate the list */
    for (n = 0; n < (arraysize(ENV) - 1); n++) {

        /* Delete any existing entry for this key */
        if (ENV[n] != NULL) {
            size_t entry_key_len = strcspn(ENV[n], "=");
            if ((entry_key_len == key_len) && (strncmp(ENV[n], key, entry_key_len) == 0)) {
                free((char*)ENV[n]);
                ENV[n] = NULL;
            }
        }

        /* Add entry if a free slot is available */
        if (ENV[n] == NULL) {
            char* entry;
            asprintf(&entry, "%s=%s", key, val);
            ENV[n] = entry;
            return 0;
        }
    }

    LOG(ERROR) << "No env. room to store: '" << key << "':'" << val << "'";

    return -1;
}

bool start_waiting_for_property(const char *name, const char *value)
{
    if (waiting_for_prop) {
@@ -429,8 +395,6 @@ int main(int argc, char** argv) {
        install_reboot_signal_handlers();
    }

    add_environment("PATH", _PATH_DEFPATH);

    bool is_first_stage = (getenv("INIT_SECOND_STAGE") == nullptr);

    if (is_first_stage) {
@@ -439,6 +403,8 @@ int main(int argc, char** argv) {
        // Clear the umask.
        umask(0);

        clearenv();
        setenv("PATH", _PATH_DEFPATH, 1);
        // Get the basic filesystem setup we need put together in the initramdisk
        // on / and then we'll let the rc file figure out the rest.
        mount("tmpfs", "/dev", "tmpfs", MS_NOSUID, "mode=0755");
+0 −4
Original line number Diff line number Diff line
@@ -30,9 +30,7 @@ namespace init {
// Note: These globals are *only* valid in init, so they should not be used in ueventd,
// watchdogd, or any files that may be included in those, such as devices.cpp and util.cpp.
// TODO: Have an Init class and remove all globals.
extern const char *ENV[32];
extern std::string default_console;

extern std::vector<std::string> late_import_paths;

Parser CreateParser(ActionManager& action_manager, ServiceList& service_list);
@@ -43,8 +41,6 @@ void property_changed(const std::string& name, const std::string& value);

void register_epoll_handler(int fd, void (*fn)());

int add_environment(const char* key, const char* val);

bool start_waiting_for_property(const char *name, const char *value);

void DumpState();
Loading