From: Daan De Meyer Date: Mon, 3 Jun 2024 08:40:35 +0000 (+0200) Subject: core: Fix CPUQuotaPerSecUSec unit file serialization X-Git-Tag: v256-rc4~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1a48d8549f5a0281ba73558e31490f7ec98f81cc;p=thirdparty%2Fsystemd.git core: Fix CPUQuotaPerSecUSec unit file serialization CPUQuota= can deal with float percentages perfectly fine these days (up to two places after the dot), so let's take that into account when serializing the value to the transient unit file so we don't lose precision when specifying e.g. "CPUQuota=0.5%". --- diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c index 6cb335608b0..49e84b44e32 100644 --- a/src/core/dbus-cgroup.c +++ b/src/core/dbus-cgroup.c @@ -1312,11 +1312,10 @@ int bus_cgroup_set_property( if (c->cpu_quota_per_sec_usec == USEC_INFINITY) unit_write_setting(u, flags, "CPUQuota", "CPUQuota="); else - /* config_parse_cpu_quota() requires an integer, so truncating division is used on - * purpose here. */ unit_write_settingf(u, flags, "CPUQuota", - "CPUQuota=%0.f%%", - (double) (c->cpu_quota_per_sec_usec / 10000)); + "CPUQuota=" USEC_FMT ".%02" PRI_USEC "%%", + c->cpu_quota_per_sec_usec / 10000, + (c->cpu_quota_per_sec_usec % 10000) / 100); } return 1; diff --git a/test/units/TEST-26-SYSTEMCTL.sh b/test/units/TEST-26-SYSTEMCTL.sh index 117ffb81f31..ae7a5d6eb66 100755 --- a/test/units/TEST-26-SYSTEMCTL.sh +++ b/test/units/TEST-26-SYSTEMCTL.sh @@ -241,7 +241,7 @@ systemctl revert "$UNIT_NAME" systemctl set-property --runtime "$UNIT_NAME" CPUAccounting=no CPUQuota=10% systemctl cat "$UNIT_NAME" grep -r "CPUAccounting=no" "/run/systemd/system.control/${UNIT_NAME}.d/" -grep -r "CPUQuota=10%" "/run/systemd/system.control/${UNIT_NAME}.d/" +grep -r "CPUQuota=10.00%" "/run/systemd/system.control/${UNIT_NAME}.d/" systemctl revert "$UNIT_NAME" (! grep -r "CPUAccounting=" "/run/systemd/system.control/${UNIT_NAME}.d/") (! grep -r "CPUQuota=" "/run/systemd/system.control/${UNIT_NAME}.d/")