Recursively remove a tmp dir created by cgroup_test_setup. Best-effort. * Uses opendir/unlink/rmdir rather than system("rm -rf ...") to avoid * spawning a shell from the test binary. */
| 173 | * Uses opendir/unlink/rmdir rather than system("rm -rf ...") to avoid |
| 174 | * spawning a shell from the test binary. */ |
| 175 | static void cgroup_test_teardown(const char *root) { |
| 176 | DIR *d = opendir(root); |
| 177 | if (d != NULL) { |
| 178 | struct dirent *ent; |
| 179 | while ((ent = readdir(d)) != NULL) { |
| 180 | if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) { |
| 181 | continue; |
| 182 | } |
| 183 | char child[1024]; |
| 184 | snprintf(child, sizeof(child), "%s/%s", root, ent->d_name); |
| 185 | struct stat st; |
| 186 | if (stat(child, &st) == 0 && S_ISDIR(st.st_mode)) { |
| 187 | cgroup_test_teardown(child); /* recurse into subdir */ |
| 188 | } else { |
| 189 | (void)unlink(child); |
| 190 | } |
| 191 | } |
| 192 | closedir(d); |
| 193 | } |
| 194 | (void)rmdir(root); |
| 195 | } |
| 196 | |
| 197 | TEST(cgroup_v2_cpu_quota) { |
| 198 | char root[64]; |