shared: don't exclude valid min/max values for cgroup weight fields

1 and 10000 are valid cgroup weight values, but the condition was
incorrectly excluding them:

$ echo '{"userName":"crashhostarray","cpuWeight":1}' | userdbctl -F -
<stdin>:1:42: JSON field 'cpuWeight' is not in valid range 1…10000.

$ echo '{"userName":"crashhostarray","cpuWeight":10000}' | userdbctl -F -
<stdin>:1:42: JSON field 'cpuWeight' is not in valid range 1…10000.
This commit is contained in:
Frantisek Sumsal
2026-03-06 18:39:01 +01:00
parent 1e2517bf2e
commit 76ab7861ff
2 changed files with 7 additions and 3 deletions
+3 -3
View File
@@ -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;
@@ -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 -