From 9ca7e3d00d03cc5cfe42529a4770eebe02d3cca9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 6 Jul 2021 10:22:03 +0200 Subject: [PATCH] Replace format_bytes_cgroup_protection with FORMAT_BYTES_CGROUP_PROTECTION --- src/basic/format-util.h | 8 +------- src/oom/oomd-util.c | 6 ++---- src/systemctl/systemctl-show.c | 5 ++--- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/basic/format-util.h b/src/basic/format-util.h index e802a0bb1c..92bb131a91 100644 --- a/src/basic/format-util.h +++ b/src/basic/format-util.h @@ -86,10 +86,4 @@ static inline char *format_bytes(char *buf, size_t l, uint64_t t) { #define FORMAT_BYTES(t) format_bytes((char[FORMAT_BYTES_MAX]){}, FORMAT_BYTES_MAX, t) #define FORMAT_BYTES_FULL(t, flag) format_bytes_full((char[FORMAT_BYTES_MAX]){}, FORMAT_BYTES_MAX, t, flag) -static inline char *format_bytes_cgroup_protection(char *buf, size_t l, uint64_t t) { - if (t == CGROUP_LIMIT_MAX) { - (void) snprintf(buf, l, "%s", "infinity"); - return buf; - } - return format_bytes(buf, l, t); -} +#define FORMAT_BYTES_CGROUP_PROTECTION(t) (t == CGROUP_LIMIT_MAX ? "infinity" : FORMAT_BYTES(t)) diff --git a/src/oom/oomd-util.c b/src/oom/oomd-util.c index 4bf7db8c3e..ff0fc13c6f 100644 --- a/src/oom/oomd-util.c +++ b/src/oom/oomd-util.c @@ -521,8 +521,6 @@ void oomd_dump_swap_cgroup_context(const OomdCGroupContext *ctx, FILE *f, const } void oomd_dump_memory_pressure_cgroup_context(const OomdCGroupContext *ctx, FILE *f, const char *prefix) { - char mem_min[FORMAT_BYTES_MAX], mem_low[FORMAT_BYTES_MAX]; - assert(ctx); assert(f); @@ -546,8 +544,8 @@ void oomd_dump_memory_pressure_cgroup_context(const OomdCGroupContext *ctx, FILE "%s\tMemory Low: %s\n" "%s\tPgscan: %" PRIu64 "\n" "%s\tLast Pgscan: %" PRIu64 "\n", - strempty(prefix), format_bytes_cgroup_protection(mem_min, sizeof(mem_min), ctx->memory_min), - strempty(prefix), format_bytes_cgroup_protection(mem_low, sizeof(mem_low), ctx->memory_low), + strempty(prefix), FORMAT_BYTES_CGROUP_PROTECTION(ctx->memory_min), + strempty(prefix), FORMAT_BYTES_CGROUP_PROTECTION(ctx->memory_low), strempty(prefix), ctx->pgscan, strempty(prefix), ctx->last_pgscan); } diff --git a/src/systemctl/systemctl-show.c b/src/systemctl/systemctl-show.c index 00b6948cdf..fa9a9ab750 100644 --- a/src/systemctl/systemctl-show.c +++ b/src/systemctl/systemctl-show.c @@ -671,16 +671,15 @@ static void print_status_info( i->memory_swap_max != CGROUP_LIMIT_MAX || i->memory_available != CGROUP_LIMIT_MAX || i->memory_limit != CGROUP_LIMIT_MAX) { - char buf[FORMAT_BYTES_MAX]; const char *prefix = ""; printf(" ("); if (i->memory_min > 0) { - printf("%smin: %s", prefix, format_bytes_cgroup_protection(buf, sizeof(buf), i->memory_min)); + printf("%smin: %s", prefix, FORMAT_BYTES_CGROUP_PROTECTION(i->memory_min)); prefix = " "; } if (i->memory_low > 0) { - printf("%slow: %s", prefix, format_bytes_cgroup_protection(buf, sizeof(buf), i->memory_low)); + printf("%slow: %s", prefix, FORMAT_BYTES_CGROUP_PROTECTION(i->memory_low)); prefix = " "; } if (i->memory_high != CGROUP_LIMIT_MAX) { -- 2.25.1