From: Zbigniew Jędrzejewski-Szmek Date: Fri, 10 Jun 2022 12:55:00 +0000 (+0200) Subject: shared/condition: accept size suffixes for ConditionMemory X-Git-Tag: v252-rc1~824 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a61473bde52637c7527e2f68db4635fa1bdaa976;p=thirdparty%2Fsystemd.git shared/condition: accept size suffixes for ConditionMemory Fixes #23697. --- diff --git a/src/shared/condition.c b/src/shared/condition.c index 542e3f729ec..640dd96eb2b 100644 --- a/src/shared/condition.c +++ b/src/shared/condition.c @@ -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); } diff --git a/src/test/test-condition.c b/src/test/test-condition.c index a637a490ece..fb82f44d04a 100644 --- a/src/test/test-condition.c +++ b/src/test/test-condition.c @@ -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);