]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/condition: accept size suffixes for ConditionMemory
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 10 Jun 2022 12:55:00 +0000 (14:55 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 10 Jun 2022 18:50:59 +0000 (19:50 +0100)
Fixes #23697.

src/shared/condition.c
src/test/test-condition.c

index 542e3f729ec13156797024628f58ae95bba4f01e..640dd96eb2bdbedaa612a92bafd4136faafd7185 100644 (file)
@@ -329,9 +329,9 @@ static int condition_test_memory(Condition *c, char **env) {
         if (order < 0)
                 order = ORDER_GREATER_OR_EQUAL; /* default to >= check, if nothing is specified. */
 
-        r = safe_atou64(p, &k);
+        r = parse_size(p, 1024, &k);
         if (r < 0)
-                return log_debug_errno(r, "Failed to parse size: %m");
+                return log_debug_errno(r, "Failed to parse size '%s': %m", p);
 
         return test_order(CMP(m, k), order);
 }
index a637a490ece35295827ed8abf66254fc4ecdf27c..fb82f44d04a5b0b1b962633426279395bbf54dea 100644 (file)
@@ -836,6 +836,27 @@ TEST(condition_test_memory) {
         test_condition_test_memory_one("!= 18446744073709547520", true);
         test_condition_test_memory_one("<= 18446744073709547520", true);
 
+        test_condition_test_memory_one("> 100T", false);
+        test_condition_test_memory_one("= 100T", false);
+        test_condition_test_memory_one(">= 100T", false);
+        test_condition_test_memory_one("< 100T", true);
+        test_condition_test_memory_one("!= 100T", true);
+        test_condition_test_memory_one("<= 100T", true);
+
+        test_condition_test_memory_one("> 100 T", false);
+        test_condition_test_memory_one("= 100 T", false);
+        test_condition_test_memory_one(">= 100 T", false);
+        test_condition_test_memory_one("< 100 T", true);
+        test_condition_test_memory_one("!= 100 T", true);
+        test_condition_test_memory_one("<= 100 T", true);
+
+        test_condition_test_memory_one("> 100 T 1 G", false);
+        test_condition_test_memory_one("= 100 T 1 G", false);
+        test_condition_test_memory_one(">= 100 T 1 G", false);
+        test_condition_test_memory_one("< 100 T 1 G", true);
+        test_condition_test_memory_one("!= 100 T 1 G", true);
+        test_condition_test_memory_one("<= 100 T 1 G", true);
+
         assert_se(asprintf(&t, "= %" PRIu64, memory) >= 0);
         test_condition_test_memory_one(t, true);
         t = mfree(t);