]> git.ipfire.org Git - pakfire.git/commitdiff
builds: Create a new cgroup
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 8 Aug 2022 15:23:50 +0000 (15:23 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 8 Aug 2022 15:23:50 +0000 (15:23 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c

index 6cd0edde959d0579225f5fc6056da79b3c596e19..5041f4aca37387408e28763bdbed9d9dce65839f 100644 (file)
@@ -26,6 +26,7 @@
 #include <uuid/uuid.h>
 
 #include <pakfire/build.h>
+#include <pakfire/cgroup.h>
 #include <pakfire/dist.h>
 #include <pakfire/file.h>
 #include <pakfire/jail.h>
@@ -49,6 +50,10 @@ struct pakfire_build {
 
        // Build ID
        uuid_t id;
+       char _id[UUID_STR_LEN];
+
+       // cgroup
+       struct pakfire_cgroup* cgroup;
 };
 
 static const char* stages[] = {
@@ -776,6 +781,9 @@ ERROR:
 }
 
 static void pakfire_build_free(struct pakfire_build* build) {
+       if (build->cgroup)
+               pakfire_cgroup_unref(build->cgroup);
+
        pakfire_unref(build->pakfire);
        free(build);
 }
@@ -796,6 +804,35 @@ static int pakfire_build_parse_id(struct pakfire_build* build, const char* id) {
                uuid_generate_random(build->id);
        }
 
+       // Store the ID as string, too
+       uuid_unparse_lower(build->id, build->_id);
+
+       return 0;
+}
+
+/*
+       Sets up a new cgroup for this build
+*/
+static int pakfire_build_setup_cgroup(struct pakfire_build* build) {
+       char path[PATH_MAX];
+       int r;
+
+       // Compose path
+       r = pakfire_string_format(path, "pakfire/build-%s", build->_id);
+       if (r < 0) {
+               ERROR(build->pakfire, "Could not compose path for cgroup: %m\n");
+               return 1;
+       }
+
+       // Create a new cgroup
+       r = pakfire_cgroup_open(&build->cgroup, build->pakfire, path,
+               PAKFIRE_CGROUP_ENABLE_ACCOUNTING);
+       if (r) {
+               ERROR(build->pakfire, "Could not create cgroup for build %s: %m\n", build->_id);
+               return r;
+       }
+
+       // Done
        return 0;
 }
 
@@ -822,6 +859,11 @@ PAKFIRE_EXPORT int pakfire_build_create(struct pakfire_build** build,
        if (r)
                goto ERROR;
 
+       // Create cgroup
+       r = pakfire_build_setup_cgroup(b);
+       if (r)
+               goto ERROR;
+
        *build = b;
        return 0;