]> git.ipfire.org Git - pakfire.git/commitdiff
build: Make cgroup parameters configurable
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 Aug 2022 11:08:11 +0000 (11:08 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 Aug 2022 11:08:11 +0000 (11:08 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c
tests/pakfire.conf

index 92a6fde8dbb9fece5badf520f7b68b23cb61d28d..c79645fdd3e76d747b0c21b243a4601d7098684b 100644 (file)
@@ -47,7 +47,7 @@
 #define CCACHE_DIR "/var/cache/ccache"
 
 // We guarantee 2 GiB of memory to every build container
-#define PAKFIRE_BUILD_GUARANTEED_MEMORY                (size_t)2 * 1024 * 1024 * 1024
+#define PAKFIRE_BUILD_MEMORY_GUARANTEED                (size_t)2 * 1024 * 1024 * 1024
 
 // We allow only up to 2048 processes/threads for every build container
 #define PAKFIRE_BUILD_PID_LIMIT                                (size_t)2048
@@ -810,6 +810,7 @@ static int pakfire_build_set_default_target(struct pakfire_build* build) {
        Sets up a new cgroup for this build
 */
 static int pakfire_build_setup_cgroup(struct pakfire_build* build) {
+       struct pakfire_config* config = NULL;
        char path[PATH_MAX];
        int r;
 
@@ -817,7 +818,7 @@ static int pakfire_build_setup_cgroup(struct pakfire_build* build) {
        r = pakfire_string_format(path, "pakfire/build-%s", build->_id);
        if (r) {
                ERROR(build->pakfire, "Could not compose path for cgroup: %m\n");
-               return 1;
+               goto ERROR;
        }
 
        // Create a new cgroup
@@ -825,21 +826,37 @@ static int pakfire_build_setup_cgroup(struct pakfire_build* build) {
                PAKFIRE_CGROUP_ENABLE_ACCOUNTING);
        if (r) {
                ERROR(build->pakfire, "Could not create cgroup for build %s: %m\n", build->_id);
-               return r;
+               goto ERROR;
        }
 
+       // Fetch config
+       config = pakfire_get_config(build->pakfire);
+       if (!config)
+               goto ERROR;
+
        // Guarantee some minimum memory
-       r = pakfire_cgroup_set_guaranteed_memory(build->cgroup, PAKFIRE_BUILD_GUARANTEED_MEMORY);
-       if (r)
-               return r;
+       size_t memory_guaranteed = pakfire_config_get_bytes(config, "build",
+               "memory_guaranteed", PAKFIRE_BUILD_MEMORY_GUARANTEED);
+       if (memory_guaranteed) {
+               r = pakfire_cgroup_set_guaranteed_memory(build->cgroup, memory_guaranteed);
+               if (r)
+                       goto ERROR;
+       }
 
        // Set PID limit
-       r = pakfire_cgroup_set_pid_limit(build->cgroup, PAKFIRE_BUILD_PID_LIMIT);
-       if (r)
-               return r;
+       size_t pid_limit = pakfire_config_get_int(config, "build",
+               "pid_limit", PAKFIRE_BUILD_PID_LIMIT);
+       if (pid_limit) {
+               r = pakfire_cgroup_set_pid_limit(build->cgroup, pid_limit);
+               if (r)
+                       goto ERROR;
+       }
 
-       // Done
-       return 0;
+ERROR:
+       if (config)
+               pakfire_config_unref(config);
+
+       return r;
 }
 
 /*
index df7a47d9a0d710c4a0c9e736ffc52ffa5774fab5..286e70d8b3b6e7a3f090c2dd428a33927efae85a 100644 (file)
@@ -7,3 +7,11 @@ version_id     = 1
 codename       = Blah
 vendor         = Test Project
 slogan         = Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live
+
+[build]
+
+# Guaranteed memory for the build environment
+memory_guaranteed = 256M
+
+# PID limit for the build environment
+pid_limit = 512