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

Commit 06d80246 authored by Kelvin Zhang's avatar Kelvin Zhang Committed by Gerrit Code Review
Browse files

Merge "Make RemoveCgroup idempotent" into main

parents d2d7a1ff 459edb0b
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -219,6 +219,12 @@ static int RemoveCgroup(const char* cgroup, uid_t uid, int pid, unsigned int ret

    while (retries--) {
        ret = rmdir(uid_pid_path.c_str());
        // If we get an error 2 'No such file or directory' , that means the
        // cgroup is already removed, treat it as success and return 0 for
        // idempotency.
        if (ret < 0 && errno == ENOENT) {
            ret = 0;
        }
        if (!ret || errno != EBUSY || !retries) break;
        std::this_thread::sleep_for(5ms);
    }
@@ -228,6 +234,9 @@ static int RemoveCgroup(const char* cgroup, uid_t uid, int pid, unsigned int ret
        // so free up the kernel resources for the UID level cgroup.
        const auto uid_path = ConvertUidToPath(cgroup, uid);
        ret = rmdir(uid_path.c_str());
        if (ret < 0 && errno == ENOENT) {
            ret = 0;
        }
    }

    return ret;