From: Lennart Poettering Date: Fri, 1 Nov 2019 09:22:03 +0000 (+0100) Subject: cgroup: add missing OOM check, and shorten code a bit X-Git-Tag: v244-rc1~111^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F13905%2Fhead;p=thirdparty%2Fsystemd.git cgroup: add missing OOM check, and shorten code a bit cpu_set_to_range_string() can fail due to OOM. Handle that. unit_write_settingf() exists, use it instead of formatting a string beforehand. cpu_set_add_all() can fail due to OOM. Let's avoid it if we don't have to use it, just copy over the cpuset directly. --- diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c index b30318b943f..647c3a512c8 100644 --- a/src/core/dbus-cgroup.c +++ b/src/core/dbus-cgroup.c @@ -926,23 +926,23 @@ int bus_cgroup_set_property( if (!UNIT_WRITE_FLAGS_NOOP(flags)) { _cleanup_free_ char *setstr = NULL; - _cleanup_free_ char *data = NULL; CPUSet *set; setstr = cpu_set_to_range_string(&new_set); + if (!setstr) + return -ENOMEM; if (streq(name, "AllowedCPUs")) set = &c->cpuset_cpus; else set = &c->cpuset_mems; - if (asprintf(&data, "%s=%s", name, setstr) < 0) - return -ENOMEM; - cpu_set_reset(set); - cpu_set_add_all(set, &new_set); + *set = new_set; + new_set = (CPUSet) {}; + unit_invalidate_cgroup(u, CGROUP_MASK_CPUSET); - unit_write_setting(u, flags, name, data); + unit_write_settingf(u, flags, name, "%s=%s", name, setstr); } return 1;