]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journald-config: always clear threshold_bytes even when boolean value is specified
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 13 Jul 2025 03:41:43 +0000 (12:41 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 18 Jul 2025 06:27:03 +0000 (15:27 +0900)
Otherwise, previously specified threshold may not be cleared.

src/journal/journald-config.c
src/journal/test-journald-config.c

index 667111a21a2946cfb91cd6c014b5374a4dcde4d1..ff3bad5a95238ecb229e083de3e9c2ccd5d17b8c 100644 (file)
@@ -451,36 +451,43 @@ int config_parse_compress(
                 void *data,
                 void *userdata) {
 
-        JournalCompressOptionscompress = 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;
 }
 
index 89e748182eb79870beb8887c51048322bddc6bac..5eb089a8cb14ee353a7812e1994de7ead959287a 100644 (file)
         _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);