Make RemoveCgroup idempotent

When attempting to remove a cgroup, a ENOENT means this cgroup is
already removed. Treat such errno as success for idempotency.

Test: th
Bug: 308900853
Change-Id: I6ef3c25f03d185194205b3845784d284fdc4d444
diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp
index d352f0e..6d07538 100644
--- a/libprocessgroup/processgroup.cpp
+++ b/libprocessgroup/processgroup.cpp
@@ -219,6 +219,12 @@
 
     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 @@
         // 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;