From: Yu Watanabe Date: Sun, 13 Jul 2025 03:41:43 +0000 (+0900) Subject: journald-config: always clear threshold_bytes even when boolean value is specified X-Git-Tag: v258-rc1~34^2~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=208c9cf988e7f4f3ceb95c448a1609aaf9f39c9c;p=thirdparty%2Fsystemd.git journald-config: always clear threshold_bytes even when boolean value is specified Otherwise, previously specified threshold may not be cleared. --- diff --git a/src/journal/journald-config.c b/src/journal/journald-config.c index 667111a21a2..ff3bad5a952 100644 --- a/src/journal/journald-config.c +++ b/src/journal/journald-config.c @@ -451,36 +451,43 @@ int config_parse_compress( void *data, void *userdata) { - JournalCompressOptions* compress = ASSERT_PTR(data); + JournalCompressOptions *compress = ASSERT_PTR(data); int r; - assert(filename); - assert(rvalue); - if (isempty(rvalue)) { compress->enabled = true; compress->threshold_bytes = UINT64_MAX; - } else if (streq(rvalue, "1")) { + return 0; + } + + if (streq(rvalue, "1")) { log_syntax(unit, LOG_WARNING, filename, line, 0, - "Compress= ambiguously specified as 1, enabling compression with default threshold"); + "Compress= ambiguously specified as 1, enabling compression with default threshold."); compress->enabled = true; - } else if (streq(rvalue, "0")) { + compress->threshold_bytes = UINT64_MAX; + return 0; + } + + if (streq(rvalue, "0")) { log_syntax(unit, LOG_WARNING, filename, line, 0, - "Compress= ambiguously specified as 0, disabling compression"); + "Compress= ambiguously specified as 0, disabling compression."); compress->enabled = false; - } else { - r = parse_boolean(rvalue); - if (r < 0) { - r = parse_size(rvalue, 1024, &compress->threshold_bytes); - if (r < 0) - log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to parse Compress= value, ignoring: %s", rvalue); - else - compress->enabled = true; - } else - compress->enabled = r; + compress->threshold_bytes = UINT64_MAX; + return 0; + } + + r = parse_boolean(rvalue); + if (r >= 0) { + compress->enabled = r; + compress->threshold_bytes = UINT64_MAX; + return 0; } + r = parse_size(rvalue, 1024, &compress->threshold_bytes); + if (r < 0) + return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); + + compress->enabled = true; return 0; } diff --git a/src/journal/test-journald-config.c b/src/journal/test-journald-config.c index 89e748182eb..5eb089a8cb1 100644 --- a/src/journal/test-journald-config.c +++ b/src/journal/test-journald-config.c @@ -25,21 +25,21 @@ _COMPRESS_PARSE_CHECK(str, enabled, threshold, conf##__COUNTER__) TEST(config_compress) { - COMPRESS_PARSE_CHECK("yes", true, 111); - COMPRESS_PARSE_CHECK("no", false, 111); - COMPRESS_PARSE_CHECK("y", true, 111); - COMPRESS_PARSE_CHECK("n", false, 111); - COMPRESS_PARSE_CHECK("true", true, 111); - COMPRESS_PARSE_CHECK("false", false, 111); - COMPRESS_PARSE_CHECK("t", true, 111); - COMPRESS_PARSE_CHECK("f", false, 111); - COMPRESS_PARSE_CHECK("on", true, 111); - COMPRESS_PARSE_CHECK("off", false, 111); + COMPRESS_PARSE_CHECK("yes", true, UINT64_MAX); + COMPRESS_PARSE_CHECK("no", false, UINT64_MAX); + COMPRESS_PARSE_CHECK("y", true, UINT64_MAX); + COMPRESS_PARSE_CHECK("n", false, UINT64_MAX); + COMPRESS_PARSE_CHECK("true", true, UINT64_MAX); + COMPRESS_PARSE_CHECK("false", false, UINT64_MAX); + COMPRESS_PARSE_CHECK("t", true, UINT64_MAX); + COMPRESS_PARSE_CHECK("f", false, UINT64_MAX); + COMPRESS_PARSE_CHECK("on", true, UINT64_MAX); + COMPRESS_PARSE_CHECK("off", false, UINT64_MAX); /* Weird size/bool overlapping case. We preserve backward compatibility instead of assuming these are byte * counts. */ - COMPRESS_PARSE_CHECK("1", true, 111); - COMPRESS_PARSE_CHECK("0", false, 111); + COMPRESS_PARSE_CHECK("1", true, UINT64_MAX); + COMPRESS_PARSE_CHECK("0", false, UINT64_MAX); /* IEC sizing */ COMPRESS_PARSE_CHECK("1B", true, 1);