Skip to content

Commit a8aed6a

Browse files
YHNdnzjbluca
authored andcommitted
core/cgroup: for non-cached attrs, don't return ENODATA blindly
Follow-up for f17b07f Hope I won't break this thing again...
1 parent 2674782 commit a8aed6a

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/core/cgroup.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4065,7 +4065,7 @@ int unit_get_memory_accounting(Unit *u, CGroupMemoryAccountingMetric metric, uin
40654065

40664066
if (!u->cgroup_path)
40674067
/* If the cgroup is already gone, we try to find the last cached value. */
4068-
goto cache;
4068+
goto finish;
40694069

40704070
/* The root cgroup doesn't expose this information. */
40714071
if (unit_has_host_root_cgroup(u))
@@ -4085,17 +4085,18 @@ int unit_get_memory_accounting(Unit *u, CGroupMemoryAccountingMetric metric, uin
40854085
return r;
40864086
updated = r >= 0;
40874087

4088-
cache:
4089-
if (metric > _CGROUP_MEMORY_ACCOUNTING_METRIC_CACHED_LAST)
4090-
return -ENODATA;
4088+
finish:
4089+
if (metric <= _CGROUP_MEMORY_ACCOUNTING_METRIC_CACHED_LAST) {
4090+
uint64_t *last = &u->memory_accounting_last[metric];
40914091

4092-
uint64_t *last = &u->memory_accounting_last[metric];
4092+
if (updated)
4093+
*last = bytes;
4094+
else if (*last != UINT64_MAX)
4095+
bytes = *last;
4096+
else
4097+
return -ENODATA;
40934098

4094-
if (updated)
4095-
*last = bytes;
4096-
else if (*last != UINT64_MAX)
4097-
bytes = *last;
4098-
else
4099+
} else if (!updated)
40994100
return -ENODATA;
41004101

41014102
if (ret)

0 commit comments

Comments
 (0)