]> git.ipfire.org Git - pakfire.git/commitdiff
cgroups: Don't store the path to the root
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 9 Dec 2024 17:23:12 +0000 (17:23 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 9 Dec 2024 17:23:12 +0000 (17:23 +0000)
We should not need this now that we always hold the parent groups.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/cgroup.c

index 75647be480d46fc28d3c6778e68ae167c3c0b1af..06758f7fc8b237b38e1bca3c9011c75f50cd04f8 100644 (file)
@@ -64,9 +64,6 @@ struct pakfire_cgroup {
        // The parent group
        struct pakfire_cgroup* parent;
 
-       // Store the root path
-       char root[PATH_MAX];
-
        // Flags
        int flags;
 
@@ -80,31 +77,6 @@ struct pakfire_cgroup {
        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)";
@@ -169,9 +141,13 @@ static int pakfire_cgroup_setup_devices(struct pakfire_cgroup* cgroup) {
 }
 
 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;
        }
 
@@ -386,11 +362,6 @@ int pakfire_cgroup_create(struct pakfire_cgroup** cgroup,
        // 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)