From: Michael Tremer Date: Mon, 9 Dec 2024 17:23:12 +0000 (+0000) Subject: cgroups: Don't store the path to the root X-Git-Tag: 0.9.30~734 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9fd7d67d513d29d46b0abeb08f3ec25c4d600fb6;p=pakfire.git cgroups: Don't store the path to the root We should not need this now that we always hold the parent groups. Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/cgroup.c b/src/libpakfire/cgroup.c index 75647be48..06758f7fc 100644 --- a/src/libpakfire/cgroup.c +++ b/src/libpakfire/cgroup.c @@ -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)