From d4bf82fcac576d9dfbc1b837995a780dc851cd4c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 18 Jun 2017 05:18:41 -0400 Subject: [PATCH] pid1: properly encode infinity when writing CPUQuota snippet (#6141) We would write [Slice] CPUQuota=1844674407370955% which is (numerically) correct, but it seems better to just write [Slice] CPUQuota= which is interpreted as USEC_INFINITY by the parser in config_parse_cpu_quota(). Fixes #5965. --- src/core/dbus-cgroup.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c index c4067a9..12d3ca0 100644 --- a/src/core/dbus-cgroup.c +++ b/src/core/dbus-cgroup.c @@ -407,7 +407,15 @@ int bus_cgroup_set_property( if (mode != UNIT_CHECK) { c->cpu_quota_per_sec_usec = u64; unit_invalidate_cgroup(u, CGROUP_MASK_CPU); - unit_write_drop_in_private_format(u, mode, "CPUQuota", "CPUQuota=%0.f%%", (double) (c->cpu_quota_per_sec_usec / 10000)); + if (c->cpu_quota_per_sec_usec == USEC_INFINITY) + unit_write_drop_in_private_format(u, mode, "CPUQuota", + "CPUQuota="); + else + /* config_parse_cpu_quota() requires an integer, so + * truncating division is used on purpose here. */ + unit_write_drop_in_private_format(u, mode, "CPUQuota", + "CPUQuota=%0.f%%", + (double) (c->cpu_quota_per_sec_usec / 10000)); } return 1; -- 2.7.4