if (!cgroup->parent)
return pakfire_cgroup_open_root(cgroup);
- // Try to open the cgroup
- fd = openat(cgroup->parent->fd, cgroup->name, O_DIRECTORY|O_PATH|O_CLOEXEC);
- if (fd < 0) {
+ // Try creating the cgroup
+ r = mkdirat(cgroup->parent->fd, cgroup->name, 0755);
+ if (r < 0) {
switch (errno) {
- case ENOENT:
- r = mkdirat(cgroup->parent->fd, cgroup->name, 0755);
- if (r < 0) {
- ERROR(cgroup->ctx, "Could not create cgroup '%s': %m\n", cgroup->name);
- return -errno;
- }
-
- // Try opening it again
- return __pakfire_cgroup_open(cgroup);
+ case EEXIST:
+ break;
default:
- ERROR(cgroup->ctx, "Could not open cgroup '%s': %m\n", cgroup->name);
+ ERROR(cgroup->ctx, "Could not create cgroup '%s': %m\n", cgroup->name);
return -errno;
}
}
+ // Try opening the cgroup
+ fd = openat(cgroup->parent->fd, cgroup->name, O_DIRECTORY|O_PATH|O_CLOEXEC);
+ if (fd < 0) {
+ ERROR(cgroup->ctx, "Could not open cgroup %s: %m\n", cgroup->path);
+ return -errno;
+ }
+
return fd;
}