systemctl-show: make show_memory_available cover memory_available itself

Follow-up for f380473edf

This cleans up the code a bit. Also, before this commit,
if MemoryAvailable is set but show_memory_available
is false, and we have nothing else to output, empty
parenthesis is shown. This can be easily reproduced
on -.slice:

> systemctl status -- -.slice
> ...
> Memory: 1.8G ()
> ...
This commit is contained in:
Mike Yuan 2024-05-09 01:12:17 +08:00 committed by Luca Boccassi
parent d2fa7f1310
commit 8f9acf8e10

View file

@ -714,13 +714,12 @@ static void print_status_info(
if (i->memory_current != UINT64_MAX) {
printf(" Memory: %s", FORMAT_BYTES(i->memory_current));
/* Only show current swap if it ever was non-zero or is currently non-zero. In both cases
memory_swap_peak will be non-zero (and not CGROUP_LIMIT_MAX).
Only show the available memory if it was artificially limited. */
bool show_memory_zswap_current = !IN_SET(i->memory_zswap_current, 0, CGROUP_LIMIT_MAX),
show_memory_available = i->memory_high != CGROUP_LIMIT_MAX || i->memory_max != CGROUP_LIMIT_MAX;
/* Only show the available memory if it was artificially limited. */
show_memory_available = i->memory_available != CGROUP_LIMIT_MAX &&
(i->memory_high != CGROUP_LIMIT_MAX || i->memory_max != CGROUP_LIMIT_MAX);
if (show_memory_peak ||
show_memory_swap_peak ||
show_memory_swap_peak || /* We don't need to check memory_swap_current, as if peak is 0 that must also be 0 */
show_memory_zswap_current ||
show_memory_available ||
i->memory_min > 0 ||
@ -729,7 +728,6 @@ static void print_status_info(
i->memory_max != CGROUP_LIMIT_MAX || i->startup_memory_max != CGROUP_LIMIT_MAX ||
i->memory_swap_max != CGROUP_LIMIT_MAX || i->startup_memory_swap_max != CGROUP_LIMIT_MAX ||
i->memory_zswap_max != CGROUP_LIMIT_MAX || i->startup_memory_zswap_max != CGROUP_LIMIT_MAX ||
i->memory_available != CGROUP_LIMIT_MAX ||
i->memory_limit != CGROUP_LIMIT_MAX) {
const char *prefix = "";