core: add systemd-oomd implicit dependencies

This commit is contained in:
Anita Zhang 2020-10-06 00:55:05 -07:00
parent 87e2bafff9
commit a2db02253c
1 changed files with 29 additions and 0 deletions

View 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;