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

Commit 138ab0ec authored by Nick Kralevich's avatar Nick Kralevich Committed by android-build-merger
Browse files

Merge "Revert "libprocessgroup: make sure SetupCgroups is called once and only by init""

am: eac1220f

Change-Id: Ibf1ea3109f51b98ecfadf2fa6f8fa53c535c99a5
parents 5f920a0a eac1220f
Loading
Loading
Loading
Loading
+3 −19
Original line number Original line Diff line number Diff line
@@ -229,9 +229,7 @@ static bool SetupCgroup(const CgroupDescriptor&) {


static bool WriteRcFile(const std::map<std::string, CgroupDescriptor>& descriptors) {
static bool WriteRcFile(const std::map<std::string, CgroupDescriptor>& descriptors) {
    std::string cgroup_rc_path = StringPrintf("%s/%s", CGROUPS_RC_DIR, CgroupMap::CGROUPS_RC_FILE);
    std::string cgroup_rc_path = StringPrintf("%s/%s", CGROUPS_RC_DIR, CgroupMap::CGROUPS_RC_FILE);
    // Let init keep the FD open to prevent file mappings from becoming invalid
    unique_fd fd(TEMP_FAILURE_RETRY(open(cgroup_rc_path.c_str(),
    // in case the file gets deleted somehow
    static unique_fd fd(TEMP_FAILURE_RETRY(open(cgroup_rc_path.c_str(),
                                         O_CREAT | O_WRONLY | O_TRUNC | O_CLOEXEC,
                                         O_CREAT | O_WRONLY | O_TRUNC | O_CLOEXEC,
                                         S_IRUSR | S_IRGRP | S_IROTH)));
                                         S_IRUSR | S_IRGRP | S_IROTH)));
    if (fd < 0) {
    if (fd < 0) {
@@ -414,19 +412,6 @@ void CgroupMap::Print() const {
bool CgroupMap::SetupCgroups() {
bool CgroupMap::SetupCgroups() {
    std::map<std::string, CgroupDescriptor> descriptors;
    std::map<std::string, CgroupDescriptor> descriptors;


    if (getpid() != 1) {
        LOG(ERROR) << "Cgroup setup can be done only by init process";
        return false;
    }

    // Make sure we do this only one time. No need for std::call_once because
    // init is a single-threaded process
    static bool setup_done = false;
    if (setup_done) {
        LOG(WARNING) << "Attempt to call SetupCgroups more than once";
        return true;
    }

    // load cgroups.json file
    // load cgroups.json file
    if (!ReadDescriptors(&descriptors)) {
    if (!ReadDescriptors(&descriptors)) {
        LOG(ERROR) << "Failed to load cgroup description file";
        LOG(ERROR) << "Failed to load cgroup description file";
@@ -464,7 +449,6 @@ bool CgroupMap::SetupCgroups() {
        return false;
        return false;
    }
    }


    setup_done = true;
    return true;
    return true;
}
}