From 76ab7861ff8ce505cf8deff880ce2d6c1bd05e0c Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 6 Mar 2026 16:36:52 +0100 Subject: [PATCH] shared: don't exclude valid min/max values for cgroup weight fields MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1 and 10000 are valid cgroup weight values, but the condition was incorrectly excluding them: $ echo '{"userName":"crashhostarray","cpuWeight":1}' | userdbctl -F - :1:42: JSON field 'cpuWeight' is not in valid range 1…10000. $ echo '{"userName":"crashhostarray","cpuWeight":10000}' | userdbctl -F - :1:42: JSON field 'cpuWeight' is not in valid range 1…10000. --- src/shared/user-record.c | 6 +++--- test/units/TEST-74-AUX-UTILS.userdbctl.sh | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/shared/user-record.c b/src/shared/user-record.c index ff03bcafc3..6458ee93b2 100644 --- a/src/shared/user-record.c +++ b/src/shared/user-record.c @@ -554,11 +554,11 @@ static int json_dispatch_weight(const char *name, sd_json_variant *variant, sd_j return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an integer.", strna(name)); k = sd_json_variant_unsigned(variant); - if (k <= CGROUP_WEIGHT_MIN || k >= CGROUP_WEIGHT_MAX) + if (k < CGROUP_WEIGHT_MIN || k > CGROUP_WEIGHT_MAX) return json_log(variant, flags, SYNTHETIC_ERRNO(ERANGE), "JSON field '%s' is not in valid range %" PRIu64 "%s%" PRIu64 ".", - strna(name), (uint64_t) CGROUP_WEIGHT_MIN, - glyph(GLYPH_ELLIPSIS), (uint64_t) CGROUP_WEIGHT_MAX); + strna(name), CGROUP_WEIGHT_MIN, + glyph(GLYPH_ELLIPSIS), CGROUP_WEIGHT_MAX); *weight = k; return 0; diff --git a/test/units/TEST-74-AUX-UTILS.userdbctl.sh b/test/units/TEST-74-AUX-UTILS.userdbctl.sh index 42811e7415..fdfff1a65c 100755 --- a/test/units/TEST-74-AUX-UTILS.userdbctl.sh +++ b/test/units/TEST-74-AUX-UTILS.userdbctl.sh @@ -81,3 +81,7 @@ userdbctl group "$DISK_GID" | grep -F 'io.systemd.NameServiceSwitch' >/dev/null (! busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager LookupDynamicUserByName "s" disk) (! busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager LookupDynamicUserByUID "u" "$DISK_GID") systemctl stop "$UNIT" + +# Probe specific user records +echo '{"userName":"weightmin","cpuWeight":1,"ioWeight":1}' | userdbctl -F - +echo '{"userName":"weightmax","cpuWeight":10000,"ioWeight":10000}' | userdbctl -F -