]> git.ipfire.org Git - pakfire.git/commitdiff
cgroups: Store the path to the cgroup
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 10 Dec 2024 15:27:26 +0000 (15:27 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 10 Dec 2024 15:27:26 +0000 (15:27 +0000)
This is only used for debugging.

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

index 45941a677b34540b0bee6f61a5583a75469db3e6..5b490097399cb56504450adcf49533855d260f5b 100644 (file)
@@ -67,8 +67,9 @@ struct pakfire_cgroup {
        // Flags
        int flags;
 
-       // Store the name
-       char name[PATH_MAX];
+       // Store the name & path
+       char name[NAME_MAX];
+       char path[PATH_MAX];
 
        // File descriptor to cgroup
        int fd;
@@ -84,6 +85,13 @@ static const char* pakfire_cgroup_name(struct pakfire_cgroup* cgroup) {
        return cgroup->name;
 }
 
+static const char* pakfire_cgroup_path(struct pakfire_cgroup* cgroup) {
+       if (!*cgroup->path)
+               return "(root)";
+
+       return cgroup->path;
+}
+
 static int pakfire_cgroup_setup_devices(struct pakfire_cgroup* cgroup) {
        static char bpf_log_buffer[BPF_LOG_BUF_SIZE];
 
@@ -331,6 +339,13 @@ static int pakfire_cgroup_open(struct pakfire_cgroup** cgroup,
        if (r < 0)
                goto ERROR;
 
+       // Store path
+       if (c->parent) {
+               r = pakfire_path_append(c->path, c->parent->path, c->name);
+               if (r < 0)
+                       goto ERROR;
+       }
+
        // Copy flags
        c->flags = flags;
 
@@ -351,6 +366,8 @@ static int pakfire_cgroup_open(struct pakfire_cgroup** cgroup,
                goto ERROR;
 #endif
 
+       DEBUG(c->ctx, "Created cgroup %s\n", pakfire_cgroup_path(c));
+
        // Return the pointer
        *cgroup = pakfire_cgroup_ref(c);