]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: add systemd-oomd implicit dependencies
authorAnita Zhang <the.anitazha@gmail.com>
Tue, 6 Oct 2020 07:55:05 +0000 (00:55 -0700)
committerAnita Zhang <the.anitazha@gmail.com>
Thu, 8 Oct 2020 00:12:24 +0000 (17:12 -0700)
src/core/unit.c

index 0792fd8ede31de748f7f4e7dd72abacf1e3b89cc..fd73ad2949fade026f5657b068a4c684b1d2fa89 100644 (file)
@@ -1574,6 +1574,31 @@ static int unit_add_mount_dependencies(Unit *u) {
         return 0;
 }
 
+static int unit_add_oomd_dependencies(Unit *u) {
+        CGroupContext *c;
+        bool wants_oomd;
+        int r;
+
+        assert(u);
+
+        if (!u->default_dependencies)
+                return 0;
+
+        c = unit_get_cgroup_context(u);
+        if (!c)
+                return 0;
+
+        wants_oomd = (c->moom_swap == MANAGED_OOM_KILL || c->moom_mem_pressure == MANAGED_OOM_KILL);
+        if (!wants_oomd)
+                return 0;
+
+        r = unit_add_two_dependencies_by_name(u, UNIT_AFTER, UNIT_WANTS, "systemd-oomd.service", true, UNIT_DEPENDENCY_FILE);
+        if (r < 0)
+                return r;
+
+        return 0;
+}
+
 static int unit_add_startup_units(Unit *u) {
         CGroupContext *c;
 
@@ -1634,6 +1659,10 @@ int unit_load(Unit *u) {
                 if (r < 0)
                         goto fail;
 
+                r = unit_add_oomd_dependencies(u);
+                if (r < 0)
+                        goto fail;
+
                 r = unit_add_startup_units(u);
                 if (r < 0)
                         goto fail;