// The parent group
struct pakfire_cgroup* parent;
- // Store the root path
- char root[PATH_MAX];
-
// Flags
int flags;
int devicesfd;
};
-static int pakfire_cgroup_set_root(struct pakfire_cgroup* cgroup) {
- int r;
-
- // Find the current UID
- const uid_t uid = getuid();
-
- switch (uid) {
- // root
- case 0:
- r = pakfire_string_set(cgroup->root, "/sys/fs/cgroup");
- break;
-
- // unprivileged users
- default:
- r = pakfire_string_format(cgroup->root,
- "/sys/fs/cgroup/user.slice/user-%u.slice/user@%u.service", uid, uid);
- break;
- }
-
- if (r)
- ERROR(cgroup->ctx, "Could not determine cgroup root: %m\n");
-
- return r;
-}
-
static const char* pakfire_cgroup_name(struct pakfire_cgroup* cgroup) {
if (!cgroup->parent)
return "(root)";
}
static int pakfire_cgroup_open_root(struct pakfire_cgroup* cgroup) {
- int fd = open(cgroup->root, O_DIRECTORY|O_PATH|O_CLOEXEC);
+ const char* path = "/sys/fs/cgroup";
+ int fd;
+
+ // Open the root path
+ fd = open(path, O_DIRECTORY|O_PATH|O_CLOEXEC);
if (fd < 0) {
- ERROR(cgroup->ctx, "Could not open %s: %m\n", cgroup->root);
+ ERROR(cgroup->ctx, "Could not open %s: %m\n", path);
return -errno;
}
// Initialize file descriptors
c->fd = c->devicesfd = -EBADF;
- // Find the root
- r = pakfire_cgroup_set_root(c);
- if (r < 0)
- goto ERROR;
-
// Copy path
r = pakfire_string_set(c->path, path);
if (r < 0)