chiark / gitweb /
core: add startup resource control option
[elogind.git] / src / core / unit.c
index 41651bab8782ad35ab2df5b8e7df1b029d28db15..ea55c709b016752f17853ea69419c91fda96a5eb 100644 (file)
@@ -1071,6 +1071,20 @@ static int unit_add_mount_dependencies(Unit *u) {
         return 0;
 }
 
+static int unit_add_startup_units(Unit *u) {
+        CGroupContext *c;
+        int r = 0;
+
+        c = unit_get_cgroup_context(u);
+        if (c != NULL && manager_state(u->manager) == MANAGER_STARTING &&
+            (c->startup_cpu_shares_set || c->startup_blockio_weight_set)) {
+                r = set_put(u->manager->startup_units, u);
+                if (r == -EEXIST)
+                        r = 0;
+        }
+        return r;
+}
+
 int unit_load(Unit *u) {
         int r;
 
@@ -1112,6 +1126,10 @@ int unit_load(Unit *u) {
                 if (r < 0)
                         goto fail;
 
+                r = unit_add_startup_units(u);
+                if (r < 0)
+                        goto fail;
+
                 if (u->on_failure_job_mode == JOB_ISOLATE && set_size(u->dependencies[UNIT_ON_FAILURE]) > 1) {
                         log_error_unit(u->id, "More than one OnFailure= dependencies specified for %s but OnFailureJobMode=isolate set. Refusing.", u->id);
                         r = -EINVAL;