diff options
author | Michal Koutný <mkoutny@suse.com> | 2020-02-04 16:58:36 +0100 |
---|---|---|
committer | Michal Koutný <mkoutny@suse.com> | 2020-06-02 18:59:47 +0200 |
commit | 53aa85af24cda4470b6750f88e181b775385e228 (patch) | |
tree | bfa5106a4b2453a4843486187ded51ea0cd09717 /src/shared/bus-unit-util.c | |
parent | db2b8d2e2895010f3443a589c9c1f1dfb25256a6 (diff) | |
download | systemd-53aa85af24cda4470b6750f88e181b775385e228.tar.gz |
cgroup: Allow empty assignments of Memory{Low,Min}=
Currently, an empty assignment of Memory{Low,Min}= directives would be
interpretted as setting it to global default, i.e. zero. However, if we
set a runtime protection value on a unit that inherits parent's
DefaultMemory{Low,Min}=, it is not possible to revert it back to the
state where the DefaultMemory{Low,Min}= is propagated from parent
slice(s).
This patch changes the semantics of the empty assignments to explicitly
nullify any value set by the user previously. Since DBus API uses
uint64_t where 0 is a valid configuration, the patch modifies DBus API
by exploiting the variant type of property value to pass the NULL value.
Diffstat (limited to 'src/shared/bus-unit-util.c')
-rw-r--r-- | src/shared/bus-unit-util.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index 48171469a5..8155f3a250 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -494,16 +494,18 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons if (r < 0) return bus_log_create_error(r); return 1; + } else if (isempty(eq) && STR_IN_SET(field, "DefaultMemoryLow", + "DefaultMemoryMin", + "MemoryLow", + "MemoryMin")) { + /* We can't use CGROUP_LIMIT_MIN nor CGROUP_LIMIT_MAX to convey the empty assignment + * so marshall specially as a boolean. */ + r = sd_bus_message_append(m, "(sv)", field, "b", 0); + if (r < 0) + return bus_log_create_error(r); + return 1; } else if (isempty(eq)) { - uint64_t empty_value = STR_IN_SET(field, - "DefaultMemoryLow", - "DefaultMemoryMin", - "MemoryLow", - "MemoryMin") ? - CGROUP_LIMIT_MIN : - CGROUP_LIMIT_MAX; - - r = sd_bus_message_append(m, "(sv)", field, "t", empty_value); + r = sd_bus_message_append(m, "(sv)", field, "t", CGROUP_LIMIT_MAX); if (r < 0) return bus_log_create_error(r); return 1; |