1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-03-08 20:58:20 +03:00

shared/condition: accept size suffixes for ConditionMemory

Fixes #23697.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2022-06-10 14:55:00 +02:00 committed by Luca Boccassi
parent e48bc49271
commit a61473bde5
2 changed files with 23 additions and 2 deletions

View 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);
}

View 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);