1
0
mirror of https://github.com/systemd/systemd synced 2024-07-09 04:26:06 +00:00

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%".
This commit is contained in:
Daan De Meyer 2024-06-03 10:40:35 +02:00
parent 80313c5577
commit 1a48d8549f
2 changed files with 4 additions and 5 deletions

View File

@ -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;

View File

@ -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/")