1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
6 #include "alloc-util.h"
7 #include "bpf-firewall.h"
8 #include "bus-get-properties.h"
9 #include "cgroup-util.h"
11 #include "core-varlink.h"
12 #include "dbus-cgroup.h"
13 #include "dbus-util.h"
14 #include "errno-util.h"
17 #include "limits-util.h"
18 #include "path-util.h"
20 BUS_DEFINE_PROPERTY_GET(bus_property_get_tasks_max
, "t", TasksMax
, tasks_max_resolve
);
22 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_cgroup_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
);
23 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_managed_oom_mode
, managed_oom_mode
, ManagedOOMMode
);
25 static int property_get_cgroup_mask(
28 const char *interface
,
30 sd_bus_message
*reply
,
32 sd_bus_error
*error
) {
34 CGroupMask
*mask
= userdata
;
35 CGroupController ctrl
;
41 r
= sd_bus_message_open_container(reply
, 'a', "s");
45 for (ctrl
= 0; ctrl
< _CGROUP_CONTROLLER_MAX
; ctrl
++) {
46 if ((*mask
& CGROUP_CONTROLLER_TO_MASK(ctrl
)) == 0)
49 r
= sd_bus_message_append(reply
, "s", cgroup_controller_to_string(ctrl
));
54 return sd_bus_message_close_container(reply
);
57 static int property_get_delegate_controllers(
60 const char *interface
,
62 sd_bus_message
*reply
,
64 sd_bus_error
*error
) {
66 CGroupContext
*c
= userdata
;
73 return sd_bus_message_append(reply
, "as", 0);
75 return property_get_cgroup_mask(bus
, path
, interface
, property
, reply
, &c
->delegate_controllers
, error
);
78 static int property_get_cpuset(
81 const char *interface
,
83 sd_bus_message
*reply
,
85 sd_bus_error
*error
) {
87 CPUSet
*cpus
= userdata
;
88 _cleanup_free_
uint8_t *array
= NULL
;
95 (void) cpu_set_to_dbus(cpus
, &array
, &allocated
);
96 return sd_bus_message_append_array(reply
, 'y', array
, allocated
);
99 static int property_get_io_device_weight(
102 const char *interface
,
103 const char *property
,
104 sd_bus_message
*reply
,
106 sd_bus_error
*error
) {
108 CGroupContext
*c
= userdata
;
109 CGroupIODeviceWeight
*w
;
116 r
= sd_bus_message_open_container(reply
, 'a', "(st)");
120 LIST_FOREACH(device_weights
, w
, c
->io_device_weights
) {
121 r
= sd_bus_message_append(reply
, "(st)", w
->path
, w
->weight
);
126 return sd_bus_message_close_container(reply
);
129 static int property_get_io_device_limits(
132 const char *interface
,
133 const char *property
,
134 sd_bus_message
*reply
,
136 sd_bus_error
*error
) {
138 CGroupContext
*c
= userdata
;
139 CGroupIODeviceLimit
*l
;
146 r
= sd_bus_message_open_container(reply
, 'a', "(st)");
150 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
) {
151 CGroupIOLimitType type
;
153 type
= cgroup_io_limit_type_from_string(property
);
154 if (type
< 0 || l
->limits
[type
] == cgroup_io_limit_defaults
[type
])
157 r
= sd_bus_message_append(reply
, "(st)", l
->path
, l
->limits
[type
]);
162 return sd_bus_message_close_container(reply
);
165 static int property_get_io_device_latency(
168 const char *interface
,
169 const char *property
,
170 sd_bus_message
*reply
,
172 sd_bus_error
*error
) {
174 CGroupContext
*c
= userdata
;
175 CGroupIODeviceLatency
*l
;
182 r
= sd_bus_message_open_container(reply
, 'a', "(st)");
186 LIST_FOREACH(device_latencies
, l
, c
->io_device_latencies
) {
187 r
= sd_bus_message_append(reply
, "(st)", l
->path
, l
->target_usec
);
192 return sd_bus_message_close_container(reply
);
195 static int property_get_blockio_device_weight(
198 const char *interface
,
199 const char *property
,
200 sd_bus_message
*reply
,
202 sd_bus_error
*error
) {
204 CGroupContext
*c
= userdata
;
205 CGroupBlockIODeviceWeight
*w
;
212 r
= sd_bus_message_open_container(reply
, 'a', "(st)");
216 LIST_FOREACH(device_weights
, w
, c
->blockio_device_weights
) {
217 r
= sd_bus_message_append(reply
, "(st)", w
->path
, w
->weight
);
222 return sd_bus_message_close_container(reply
);
225 static int property_get_blockio_device_bandwidths(
228 const char *interface
,
229 const char *property
,
230 sd_bus_message
*reply
,
232 sd_bus_error
*error
) {
234 CGroupContext
*c
= userdata
;
235 CGroupBlockIODeviceBandwidth
*b
;
242 r
= sd_bus_message_open_container(reply
, 'a', "(st)");
246 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
249 if (streq(property
, "BlockIOReadBandwidth"))
254 if (v
== CGROUP_LIMIT_MAX
)
257 r
= sd_bus_message_append(reply
, "(st)", b
->path
, v
);
262 return sd_bus_message_close_container(reply
);
265 static int property_get_device_allow(
268 const char *interface
,
269 const char *property
,
270 sd_bus_message
*reply
,
272 sd_bus_error
*error
) {
274 CGroupContext
*c
= userdata
;
275 CGroupDeviceAllow
*a
;
282 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
286 LIST_FOREACH(device_allow
, a
, c
->device_allow
) {
299 r
= sd_bus_message_append(reply
, "(ss)", a
->path
, rwm
);
304 return sd_bus_message_close_container(reply
);
307 static int property_get_ip_address_access(
310 const char *interface
,
311 const char *property
,
312 sd_bus_message
*reply
,
314 sd_bus_error
*error
) {
316 IPAddressAccessItem
** items
= userdata
, *i
;
319 r
= sd_bus_message_open_container(reply
, 'a', "(iayu)");
323 LIST_FOREACH(items
, i
, *items
) {
325 r
= sd_bus_message_open_container(reply
, 'r', "iayu");
329 r
= sd_bus_message_append(reply
, "i", i
->family
);
333 r
= sd_bus_message_append_array(reply
, 'y', &i
->address
, FAMILY_ADDRESS_SIZE(i
->family
));
337 r
= sd_bus_message_append(reply
, "u", (uint32_t) i
->prefixlen
);
341 r
= sd_bus_message_close_container(reply
);
346 return sd_bus_message_close_container(reply
);
349 const sd_bus_vtable bus_cgroup_vtable
[] = {
350 SD_BUS_VTABLE_START(0),
351 SD_BUS_PROPERTY("Delegate", "b", bus_property_get_bool
, offsetof(CGroupContext
, delegate
), 0),
352 SD_BUS_PROPERTY("DelegateControllers", "as", property_get_delegate_controllers
, 0, 0),
353 SD_BUS_PROPERTY("CPUAccounting", "b", bus_property_get_bool
, offsetof(CGroupContext
, cpu_accounting
), 0),
354 SD_BUS_PROPERTY("CPUWeight", "t", NULL
, offsetof(CGroupContext
, cpu_weight
), 0),
355 SD_BUS_PROPERTY("StartupCPUWeight", "t", NULL
, offsetof(CGroupContext
, startup_cpu_weight
), 0),
356 SD_BUS_PROPERTY("CPUShares", "t", NULL
, offsetof(CGroupContext
, cpu_shares
), 0),
357 SD_BUS_PROPERTY("StartupCPUShares", "t", NULL
, offsetof(CGroupContext
, startup_cpu_shares
), 0),
358 SD_BUS_PROPERTY("CPUQuotaPerSecUSec", "t", bus_property_get_usec
, offsetof(CGroupContext
, cpu_quota_per_sec_usec
), 0),
359 SD_BUS_PROPERTY("CPUQuotaPeriodUSec", "t", bus_property_get_usec
, offsetof(CGroupContext
, cpu_quota_period_usec
), 0),
360 SD_BUS_PROPERTY("AllowedCPUs", "ay", property_get_cpuset
, offsetof(CGroupContext
, cpuset_cpus
), 0),
361 SD_BUS_PROPERTY("AllowedMemoryNodes", "ay", property_get_cpuset
, offsetof(CGroupContext
, cpuset_mems
), 0),
362 SD_BUS_PROPERTY("IOAccounting", "b", bus_property_get_bool
, offsetof(CGroupContext
, io_accounting
), 0),
363 SD_BUS_PROPERTY("IOWeight", "t", NULL
, offsetof(CGroupContext
, io_weight
), 0),
364 SD_BUS_PROPERTY("StartupIOWeight", "t", NULL
, offsetof(CGroupContext
, startup_io_weight
), 0),
365 SD_BUS_PROPERTY("IODeviceWeight", "a(st)", property_get_io_device_weight
, 0, 0),
366 SD_BUS_PROPERTY("IOReadBandwidthMax", "a(st)", property_get_io_device_limits
, 0, 0),
367 SD_BUS_PROPERTY("IOWriteBandwidthMax", "a(st)", property_get_io_device_limits
, 0, 0),
368 SD_BUS_PROPERTY("IOReadIOPSMax", "a(st)", property_get_io_device_limits
, 0, 0),
369 SD_BUS_PROPERTY("IOWriteIOPSMax", "a(st)", property_get_io_device_limits
, 0, 0),
370 SD_BUS_PROPERTY("IODeviceLatencyTargetUSec", "a(st)", property_get_io_device_latency
, 0, 0),
371 SD_BUS_PROPERTY("BlockIOAccounting", "b", bus_property_get_bool
, offsetof(CGroupContext
, blockio_accounting
), 0),
372 SD_BUS_PROPERTY("BlockIOWeight", "t", NULL
, offsetof(CGroupContext
, blockio_weight
), 0),
373 SD_BUS_PROPERTY("StartupBlockIOWeight", "t", NULL
, offsetof(CGroupContext
, startup_blockio_weight
), 0),
374 SD_BUS_PROPERTY("BlockIODeviceWeight", "a(st)", property_get_blockio_device_weight
, 0, 0),
375 SD_BUS_PROPERTY("BlockIOReadBandwidth", "a(st)", property_get_blockio_device_bandwidths
, 0, 0),
376 SD_BUS_PROPERTY("BlockIOWriteBandwidth", "a(st)", property_get_blockio_device_bandwidths
, 0, 0),
377 SD_BUS_PROPERTY("MemoryAccounting", "b", bus_property_get_bool
, offsetof(CGroupContext
, memory_accounting
), 0),
378 SD_BUS_PROPERTY("DefaultMemoryLow", "t", NULL
, offsetof(CGroupContext
, default_memory_low
), 0),
379 SD_BUS_PROPERTY("DefaultMemoryMin", "t", NULL
, offsetof(CGroupContext
, default_memory_min
), 0),
380 SD_BUS_PROPERTY("MemoryMin", "t", NULL
, offsetof(CGroupContext
, memory_min
), 0),
381 SD_BUS_PROPERTY("MemoryLow", "t", NULL
, offsetof(CGroupContext
, memory_low
), 0),
382 SD_BUS_PROPERTY("MemoryHigh", "t", NULL
, offsetof(CGroupContext
, memory_high
), 0),
383 SD_BUS_PROPERTY("MemoryMax", "t", NULL
, offsetof(CGroupContext
, memory_max
), 0),
384 SD_BUS_PROPERTY("MemorySwapMax", "t", NULL
, offsetof(CGroupContext
, memory_swap_max
), 0),
385 SD_BUS_PROPERTY("MemoryLimit", "t", NULL
, offsetof(CGroupContext
, memory_limit
), 0),
386 SD_BUS_PROPERTY("DevicePolicy", "s", property_get_cgroup_device_policy
, offsetof(CGroupContext
, device_policy
), 0),
387 SD_BUS_PROPERTY("DeviceAllow", "a(ss)", property_get_device_allow
, 0, 0),
388 SD_BUS_PROPERTY("TasksAccounting", "b", bus_property_get_bool
, offsetof(CGroupContext
, tasks_accounting
), 0),
389 SD_BUS_PROPERTY("TasksMax", "t", bus_property_get_tasks_max
, offsetof(CGroupContext
, tasks_max
), 0),
390 SD_BUS_PROPERTY("IPAccounting", "b", bus_property_get_bool
, offsetof(CGroupContext
, ip_accounting
), 0),
391 SD_BUS_PROPERTY("IPAddressAllow", "a(iayu)", property_get_ip_address_access
, offsetof(CGroupContext
, ip_address_allow
), 0),
392 SD_BUS_PROPERTY("IPAddressDeny", "a(iayu)", property_get_ip_address_access
, offsetof(CGroupContext
, ip_address_deny
), 0),
393 SD_BUS_PROPERTY("IPIngressFilterPath", "as", NULL
, offsetof(CGroupContext
, ip_filters_ingress
), 0),
394 SD_BUS_PROPERTY("IPEgressFilterPath", "as", NULL
, offsetof(CGroupContext
, ip_filters_egress
), 0),
395 SD_BUS_PROPERTY("DisableControllers", "as", property_get_cgroup_mask
, offsetof(CGroupContext
, disable_controllers
), 0),
396 SD_BUS_PROPERTY("ManagedOOMSwap", "s", property_get_managed_oom_mode
, offsetof(CGroupContext
, moom_swap
), 0),
397 SD_BUS_PROPERTY("ManagedOOMMemoryPressure", "s", property_get_managed_oom_mode
, offsetof(CGroupContext
, moom_mem_pressure
), 0),
398 SD_BUS_PROPERTY("ManagedOOMMemoryPressureLimitPercent", "s", bus_property_get_percent
, offsetof(CGroupContext
, moom_mem_pressure_limit
), 0),
402 static int bus_cgroup_set_transient_property(
406 sd_bus_message
*message
,
407 UnitWriteFlags flags
,
408 sd_bus_error
*error
) {
417 flags
|= UNIT_PRIVATE
;
419 if (streq(name
, "Delegate")) {
422 if (!UNIT_VTABLE(u
)->can_delegate
)
423 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Delegation not available for unit type");
425 r
= sd_bus_message_read(message
, "b", &b
);
429 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
431 c
->delegate_controllers
= b
? _CGROUP_MASK_ALL
: 0;
433 unit_write_settingf(u
, flags
, name
, "Delegate=%s", yes_no(b
));
438 } else if (STR_IN_SET(name
, "DelegateControllers", "DisableControllers")) {
441 if (streq(name
, "DelegateControllers") && !UNIT_VTABLE(u
)->can_delegate
)
442 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Delegation not available for unit type");
444 r
= sd_bus_message_enter_container(message
, 'a', "s");
452 r
= sd_bus_message_read(message
, "s", &t
);
458 cc
= cgroup_controller_from_string(t
);
460 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unknown cgroup controller '%s'", t
);
462 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
465 r
= sd_bus_message_exit_container(message
);
469 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
470 _cleanup_free_
char *t
= NULL
;
472 r
= cg_mask_to_string(mask
, &t
);
476 if (streq(name
, "DelegateControllers")) {
480 c
->delegate_controllers
= 0;
482 c
->delegate_controllers
|= mask
;
484 unit_write_settingf(u
, flags
, name
, "Delegate=%s", strempty(t
));
486 } else if (streq(name
, "DisableControllers")) {
489 c
->disable_controllers
= 0;
491 c
->disable_controllers
|= mask
;
493 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, strempty(t
));
498 } else if (STR_IN_SET(name
, "IPIngressFilterPath", "IPEgressFilterPath")) {
502 filters
= streq(name
, "IPIngressFilterPath") ? &c
->ip_filters_ingress
: &c
->ip_filters_egress
;
503 r
= sd_bus_message_enter_container(message
, 'a', "s");
510 r
= sd_bus_message_read(message
, "s", &path
);
516 if (!path_is_normalized(path
) || !path_is_absolute(path
))
517 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= expects a normalized absolute path.", name
);
519 if (!UNIT_WRITE_FLAGS_NOOP(flags
) && !strv_contains(*filters
, path
)) {
520 r
= strv_extend(filters
, path
);
526 r
= sd_bus_message_exit_container(message
);
530 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
531 _cleanup_free_
char *buf
= NULL
;
532 _cleanup_fclose_
FILE *f
= NULL
;
537 *filters
= strv_free(*filters
);
539 unit_invalidate_cgroup_bpf(u
);
540 f
= open_memstream_unlocked(&buf
, &size
);
547 STRV_FOREACH(entry
, *filters
)
548 fprintf(f
, "%s=%s\n", name
, *entry
);
550 r
= fflush_and_check(f
);
554 unit_write_setting(u
, flags
, name
, buf
);
557 r
= bpf_firewall_supported();
560 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
561 static bool warned
= false;
563 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
564 "Transient unit %s configures an IP firewall with BPF, but the local system does not support BPF/cgroup firewalling with multiple filters.\n"
565 "Starting this unit will fail! (This warning is only shown for the first started transient unit using IP firewalling.)", u
->id
);
577 static int bus_cgroup_set_boolean(
582 sd_bus_message
*message
,
583 UnitWriteFlags flags
,
584 sd_bus_error
*error
) {
590 r
= sd_bus_message_read(message
, "b", &b
);
594 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
596 unit_invalidate_cgroup(u
, mask
);
597 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, yes_no(b
));
603 #define BUS_DEFINE_SET_CGROUP_WEIGHT(function, mask, check, val) \
604 static int bus_cgroup_set_##function( \
608 sd_bus_message *message, \
609 UnitWriteFlags flags, \
610 sd_bus_error *error) { \
617 r = sd_bus_message_read(message, "t", &v); \
622 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, \
623 "Value specified in %s is out of range", name); \
625 if (!UNIT_WRITE_FLAGS_NOOP(flags)) { \
627 unit_invalidate_cgroup(u, mask); \
630 unit_write_settingf(u, flags, name, \
633 unit_write_settingf(u, flags, name, \
634 "%s=%" PRIu64, name, v); \
640 #define BUS_DEFINE_SET_CGROUP_LIMIT(function, mask, scale, minimum) \
641 static int bus_cgroup_set_##function( \
645 sd_bus_message *message, \
646 UnitWriteFlags flags, \
647 sd_bus_error *error) { \
654 r = sd_bus_message_read(message, "t", &v); \
659 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, \
660 "Value specified in %s is out of range", name); \
662 if (!UNIT_WRITE_FLAGS_NOOP(flags)) { \
664 unit_invalidate_cgroup(u, mask); \
666 if (v == CGROUP_LIMIT_MAX) \
667 unit_write_settingf(u, flags, name, \
668 "%s=infinity", name); \
670 unit_write_settingf(u, flags, name, \
671 "%s=%" PRIu64, name, v); \
676 static int bus_cgroup_set_##function##_scale( \
680 sd_bus_message *message, \
681 UnitWriteFlags flags, \
682 sd_bus_error *error) { \
690 r = sd_bus_message_read(message, "u", &raw); \
694 v = scale(raw, UINT32_MAX); \
695 if (v < minimum || v >= UINT64_MAX) \
696 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, \
697 "Value specified in %s is out of range", name); \
699 if (!UNIT_WRITE_FLAGS_NOOP(flags)) { \
701 unit_invalidate_cgroup(u, mask); \
703 /* Prepare to chop off suffix */ \
704 assert_se(endswith(name, "Scale")); \
706 uint32_t scaled = DIV_ROUND_UP((uint64_t) raw * 1000, (uint64_t) UINT32_MAX); \
707 unit_write_settingf(u, flags, name, "%.*s=%" PRIu32 ".%" PRIu32 "%%", \
708 (int)(strlen(name) - strlen("Scale")), name, \
709 scaled / 10, scaled % 10); \
715 DISABLE_WARNING_TYPE_LIMITS
;
716 BUS_DEFINE_SET_CGROUP_WEIGHT(cpu_weight
, CGROUP_MASK_CPU
, CGROUP_WEIGHT_IS_OK
, CGROUP_WEIGHT_INVALID
);
717 BUS_DEFINE_SET_CGROUP_WEIGHT(cpu_shares
, CGROUP_MASK_CPU
, CGROUP_CPU_SHARES_IS_OK
, CGROUP_CPU_SHARES_INVALID
);
718 BUS_DEFINE_SET_CGROUP_WEIGHT(io_weight
, CGROUP_MASK_IO
, CGROUP_WEIGHT_IS_OK
, CGROUP_WEIGHT_INVALID
);
719 BUS_DEFINE_SET_CGROUP_WEIGHT(blockio_weight
, CGROUP_MASK_BLKIO
, CGROUP_BLKIO_WEIGHT_IS_OK
, CGROUP_BLKIO_WEIGHT_INVALID
);
720 BUS_DEFINE_SET_CGROUP_LIMIT(memory
, CGROUP_MASK_MEMORY
, physical_memory_scale
, 1);
721 BUS_DEFINE_SET_CGROUP_LIMIT(memory_protection
, CGROUP_MASK_MEMORY
, physical_memory_scale
, 0);
722 BUS_DEFINE_SET_CGROUP_LIMIT(swap
, CGROUP_MASK_MEMORY
, physical_memory_scale
, 0);
725 static int bus_cgroup_set_tasks_max(
729 sd_bus_message
*message
,
730 UnitWriteFlags flags
,
731 sd_bus_error
*error
) {
738 r
= sd_bus_message_read(message
, "t", &v
);
743 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
,
744 "Value specified in %s is out of range", name
);
746 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
747 *p
= (TasksMax
) { .value
= v
, .scale
= 0 }; /* When .scale==0, .value is the absolute value */
748 unit_invalidate_cgroup(u
, CGROUP_MASK_PIDS
);
750 if (v
== CGROUP_LIMIT_MAX
)
751 unit_write_settingf(u
, flags
, name
,
752 "%s=infinity", name
);
754 unit_write_settingf(u
, flags
, name
,
755 "%s=%" PRIu64
, name
, v
);
761 static int bus_cgroup_set_tasks_max_scale(
765 sd_bus_message
*message
,
766 UnitWriteFlags flags
,
767 sd_bus_error
*error
) {
774 r
= sd_bus_message_read(message
, "u", &v
);
778 if (v
< 1 || v
>= UINT32_MAX
)
779 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
,
780 "Value specified in %s is out of range", name
);
782 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
783 *p
= (TasksMax
) { v
, UINT32_MAX
}; /* .scale is not 0, so this is interpreted as v/UINT32_MAX. */
784 unit_invalidate_cgroup(u
, CGROUP_MASK_PIDS
);
786 uint32_t scaled
= DIV_ROUND_UP((uint64_t) v
* 100U, (uint64_t) UINT32_MAX
);
787 unit_write_settingf(u
, flags
, name
, "%s=%" PRIu32
".%" PRIu32
"%%", "TasksMax",
788 scaled
/ 10, scaled
% 10);
794 int bus_cgroup_set_property(
798 sd_bus_message
*message
,
799 UnitWriteFlags flags
,
800 sd_bus_error
*error
) {
802 CGroupIOLimitType iol_type
;
810 flags
|= UNIT_PRIVATE
;
812 if (streq(name
, "CPUAccounting"))
813 return bus_cgroup_set_boolean(u
, name
, &c
->cpu_accounting
, get_cpu_accounting_mask(), message
, flags
, error
);
815 if (streq(name
, "CPUWeight"))
816 return bus_cgroup_set_cpu_weight(u
, name
, &c
->cpu_weight
, message
, flags
, error
);
818 if (streq(name
, "StartupCPUWeight"))
819 return bus_cgroup_set_cpu_weight(u
, name
, &c
->startup_cpu_weight
, message
, flags
, error
);
821 if (streq(name
, "CPUShares"))
822 return bus_cgroup_set_cpu_shares(u
, name
, &c
->cpu_shares
, message
, flags
, error
);
824 if (streq(name
, "StartupCPUShares"))
825 return bus_cgroup_set_cpu_shares(u
, name
, &c
->startup_cpu_shares
, message
, flags
, error
);
827 if (streq(name
, "IOAccounting"))
828 return bus_cgroup_set_boolean(u
, name
, &c
->io_accounting
, CGROUP_MASK_IO
, message
, flags
, error
);
830 if (streq(name
, "IOWeight"))
831 return bus_cgroup_set_io_weight(u
, name
, &c
->io_weight
, message
, flags
, error
);
833 if (streq(name
, "StartupIOWeight"))
834 return bus_cgroup_set_io_weight(u
, name
, &c
->startup_io_weight
, message
, flags
, error
);
836 if (streq(name
, "BlockIOAccounting"))
837 return bus_cgroup_set_boolean(u
, name
, &c
->blockio_accounting
, CGROUP_MASK_BLKIO
, message
, flags
, error
);
839 if (streq(name
, "BlockIOWeight"))
840 return bus_cgroup_set_blockio_weight(u
, name
, &c
->blockio_weight
, message
, flags
, error
);
842 if (streq(name
, "StartupBlockIOWeight"))
843 return bus_cgroup_set_blockio_weight(u
, name
, &c
->startup_blockio_weight
, message
, flags
, error
);
845 if (streq(name
, "MemoryAccounting"))
846 return bus_cgroup_set_boolean(u
, name
, &c
->memory_accounting
, CGROUP_MASK_MEMORY
, message
, flags
, error
);
848 if (streq(name
, "MemoryMin")) {
849 r
= bus_cgroup_set_memory_protection(u
, name
, &c
->memory_min
, message
, flags
, error
);
851 c
->memory_min_set
= true;
855 if (streq(name
, "MemoryLow")) {
856 r
= bus_cgroup_set_memory_protection(u
, name
, &c
->memory_low
, message
, flags
, error
);
858 c
->memory_low_set
= true;
862 if (streq(name
, "DefaultMemoryMin")) {
863 r
= bus_cgroup_set_memory_protection(u
, name
, &c
->default_memory_min
, message
, flags
, error
);
865 c
->default_memory_min_set
= true;
869 if (streq(name
, "DefaultMemoryLow")) {
870 r
= bus_cgroup_set_memory_protection(u
, name
, &c
->default_memory_low
, message
, flags
, error
);
872 c
->default_memory_low_set
= true;
876 if (streq(name
, "MemoryHigh"))
877 return bus_cgroup_set_memory(u
, name
, &c
->memory_high
, message
, flags
, error
);
879 if (streq(name
, "MemorySwapMax"))
880 return bus_cgroup_set_swap(u
, name
, &c
->memory_swap_max
, message
, flags
, error
);
882 if (streq(name
, "MemoryMax"))
883 return bus_cgroup_set_memory(u
, name
, &c
->memory_max
, message
, flags
, error
);
885 if (streq(name
, "MemoryLimit"))
886 return bus_cgroup_set_memory(u
, name
, &c
->memory_limit
, message
, flags
, error
);
888 if (streq(name
, "MemoryMinScale")) {
889 r
= bus_cgroup_set_memory_protection_scale(u
, name
, &c
->memory_min
, message
, flags
, error
);
891 c
->memory_min_set
= true;
895 if (streq(name
, "MemoryLowScale")) {
896 r
= bus_cgroup_set_memory_protection_scale(u
, name
, &c
->memory_low
, message
, flags
, error
);
898 c
->memory_low_set
= true;
902 if (streq(name
, "DefaultMemoryMinScale")) {
903 r
= bus_cgroup_set_memory_protection_scale(u
, name
, &c
->default_memory_min
, message
, flags
, error
);
905 c
->default_memory_min_set
= true;
909 if (streq(name
, "DefaultMemoryLowScale")) {
910 r
= bus_cgroup_set_memory_protection_scale(u
, name
, &c
->default_memory_low
, message
, flags
, error
);
912 c
->default_memory_low_set
= true;
916 if (streq(name
, "MemoryHighScale"))
917 return bus_cgroup_set_memory_scale(u
, name
, &c
->memory_high
, message
, flags
, error
);
919 if (streq(name
, "MemorySwapMaxScale"))
920 return bus_cgroup_set_swap_scale(u
, name
, &c
->memory_swap_max
, message
, flags
, error
);
922 if (streq(name
, "MemoryMaxScale"))
923 return bus_cgroup_set_memory_scale(u
, name
, &c
->memory_max
, message
, flags
, error
);
925 if (streq(name
, "MemoryLimitScale"))
926 return bus_cgroup_set_memory_scale(u
, name
, &c
->memory_limit
, message
, flags
, error
);
928 if (streq(name
, "TasksAccounting"))
929 return bus_cgroup_set_boolean(u
, name
, &c
->tasks_accounting
, CGROUP_MASK_PIDS
, message
, flags
, error
);
931 if (streq(name
, "TasksMax"))
932 return bus_cgroup_set_tasks_max(u
, name
, &c
->tasks_max
, message
, flags
, error
);
934 if (streq(name
, "TasksMaxScale"))
935 return bus_cgroup_set_tasks_max_scale(u
, name
, &c
->tasks_max
, message
, flags
, error
);
937 if (streq(name
, "CPUQuotaPerSecUSec")) {
940 r
= sd_bus_message_read(message
, "t", &u64
);
945 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "CPUQuotaPerSecUSec= value out of range");
947 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
948 c
->cpu_quota_per_sec_usec
= u64
;
949 u
->warned_clamping_cpu_quota_period
= false;
950 unit_invalidate_cgroup(u
, CGROUP_MASK_CPU
);
952 if (c
->cpu_quota_per_sec_usec
== USEC_INFINITY
)
953 unit_write_setting(u
, flags
, "CPUQuota", "CPUQuota=");
955 /* config_parse_cpu_quota() requires an integer, so truncating division is used on
957 unit_write_settingf(u
, flags
, "CPUQuota",
959 (double) (c
->cpu_quota_per_sec_usec
/ 10000));
964 } else if (streq(name
, "CPUQuotaPeriodUSec")) {
967 r
= sd_bus_message_read(message
, "t", &u64
);
971 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
972 c
->cpu_quota_period_usec
= u64
;
973 u
->warned_clamping_cpu_quota_period
= false;
974 unit_invalidate_cgroup(u
, CGROUP_MASK_CPU
);
975 if (c
->cpu_quota_period_usec
== USEC_INFINITY
)
976 unit_write_setting(u
, flags
, "CPUQuotaPeriodSec", "CPUQuotaPeriodSec=");
978 char v
[FORMAT_TIMESPAN_MAX
];
979 unit_write_settingf(u
, flags
, "CPUQuotaPeriodSec",
980 "CPUQuotaPeriodSec=%s",
981 format_timespan(v
, sizeof(v
), c
->cpu_quota_period_usec
, 1));
987 } else if (STR_IN_SET(name
, "AllowedCPUs", "AllowedMemoryNodes")) {
990 _cleanup_(cpu_set_reset
) CPUSet new_set
= {};
992 r
= sd_bus_message_read_array(message
, 'y', &a
, &n
);
996 r
= cpu_set_from_dbus(a
, n
, &new_set
);
1000 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1001 _cleanup_free_
char *setstr
= NULL
;
1004 setstr
= cpu_set_to_range_string(&new_set
);
1008 if (streq(name
, "AllowedCPUs"))
1009 set
= &c
->cpuset_cpus
;
1011 set
= &c
->cpuset_mems
;
1015 new_set
= (CPUSet
) {};
1017 unit_invalidate_cgroup(u
, CGROUP_MASK_CPUSET
);
1018 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, setstr
);
1023 } else if ((iol_type
= cgroup_io_limit_type_from_string(name
)) >= 0) {
1028 r
= sd_bus_message_enter_container(message
, 'a', "(st)");
1032 while ((r
= sd_bus_message_read(message
, "(st)", &path
, &u64
)) > 0) {
1034 if (!path_is_normalized(path
))
1035 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path '%s' specified in %s= is not normalized.", name
, path
);
1037 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1038 CGroupIODeviceLimit
*a
= NULL
, *b
;
1040 LIST_FOREACH(device_limits
, b
, c
->io_device_limits
) {
1041 if (path_equal(path
, b
->path
)) {
1048 CGroupIOLimitType type
;
1050 a
= new0(CGroupIODeviceLimit
, 1);
1054 a
->path
= strdup(path
);
1060 for (type
= 0; type
< _CGROUP_IO_LIMIT_TYPE_MAX
; type
++)
1061 a
->limits
[type
] = cgroup_io_limit_defaults
[type
];
1063 LIST_PREPEND(device_limits
, c
->io_device_limits
, a
);
1066 a
->limits
[iol_type
] = u64
;
1074 r
= sd_bus_message_exit_container(message
);
1078 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1079 CGroupIODeviceLimit
*a
;
1080 _cleanup_free_
char *buf
= NULL
;
1081 _cleanup_fclose_
FILE *f
= NULL
;
1085 LIST_FOREACH(device_limits
, a
, c
->io_device_limits
)
1086 a
->limits
[iol_type
] = cgroup_io_limit_defaults
[iol_type
];
1089 unit_invalidate_cgroup(u
, CGROUP_MASK_IO
);
1091 f
= open_memstream_unlocked(&buf
, &size
);
1095 fprintf(f
, "%s=\n", name
);
1096 LIST_FOREACH(device_limits
, a
, c
->io_device_limits
)
1097 if (a
->limits
[iol_type
] != cgroup_io_limit_defaults
[iol_type
])
1098 fprintf(f
, "%s=%s %" PRIu64
"\n", name
, a
->path
, a
->limits
[iol_type
]);
1100 r
= fflush_and_check(f
);
1103 unit_write_setting(u
, flags
, name
, buf
);
1108 } else if (streq(name
, "IODeviceWeight")) {
1113 r
= sd_bus_message_enter_container(message
, 'a', "(st)");
1117 while ((r
= sd_bus_message_read(message
, "(st)", &path
, &weight
)) > 0) {
1119 if (!path_is_normalized(path
))
1120 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path '%s' specified in %s= is not normalized.", name
, path
);
1122 if (!CGROUP_WEIGHT_IS_OK(weight
) || weight
== CGROUP_WEIGHT_INVALID
)
1123 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "IODeviceWeight= value out of range");
1125 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1126 CGroupIODeviceWeight
*a
= NULL
, *b
;
1128 LIST_FOREACH(device_weights
, b
, c
->io_device_weights
) {
1129 if (path_equal(b
->path
, path
)) {
1136 a
= new0(CGroupIODeviceWeight
, 1);
1140 a
->path
= strdup(path
);
1145 LIST_PREPEND(device_weights
, c
->io_device_weights
, a
);
1154 r
= sd_bus_message_exit_container(message
);
1158 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1159 _cleanup_free_
char *buf
= NULL
;
1160 _cleanup_fclose_
FILE *f
= NULL
;
1161 CGroupIODeviceWeight
*a
;
1165 while (c
->io_device_weights
)
1166 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
1169 unit_invalidate_cgroup(u
, CGROUP_MASK_IO
);
1171 f
= open_memstream_unlocked(&buf
, &size
);
1175 fputs("IODeviceWeight=\n", f
);
1176 LIST_FOREACH(device_weights
, a
, c
->io_device_weights
)
1177 fprintf(f
, "IODeviceWeight=%s %" PRIu64
"\n", a
->path
, a
->weight
);
1179 r
= fflush_and_check(f
);
1182 unit_write_setting(u
, flags
, name
, buf
);
1187 } else if (streq(name
, "IODeviceLatencyTargetUSec")) {
1192 r
= sd_bus_message_enter_container(message
, 'a', "(st)");
1196 while ((r
= sd_bus_message_read(message
, "(st)", &path
, &target
)) > 0) {
1198 if (!path_is_normalized(path
))
1199 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path '%s' specified in %s= is not normalized.", name
, path
);
1201 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1202 CGroupIODeviceLatency
*a
= NULL
, *b
;
1204 LIST_FOREACH(device_latencies
, b
, c
->io_device_latencies
) {
1205 if (path_equal(b
->path
, path
)) {
1212 a
= new0(CGroupIODeviceLatency
, 1);
1216 a
->path
= strdup(path
);
1221 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, a
);
1224 a
->target_usec
= target
;
1230 r
= sd_bus_message_exit_container(message
);
1234 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1235 _cleanup_free_
char *buf
= NULL
;
1236 _cleanup_fclose_
FILE *f
= NULL
;
1237 char ts
[FORMAT_TIMESPAN_MAX
];
1238 CGroupIODeviceLatency
*a
;
1242 while (c
->io_device_latencies
)
1243 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
1246 unit_invalidate_cgroup(u
, CGROUP_MASK_IO
);
1248 f
= open_memstream_unlocked(&buf
, &size
);
1252 fputs("IODeviceLatencyTargetSec=\n", f
);
1253 LIST_FOREACH(device_latencies
, a
, c
->io_device_latencies
)
1254 fprintf(f
, "IODeviceLatencyTargetSec=%s %s\n",
1255 a
->path
, format_timespan(ts
, sizeof(ts
), a
->target_usec
, 1));
1257 r
= fflush_and_check(f
);
1260 unit_write_setting(u
, flags
, name
, buf
);
1265 } else if (STR_IN_SET(name
, "BlockIOReadBandwidth", "BlockIOWriteBandwidth")) {
1271 if (streq(name
, "BlockIOWriteBandwidth"))
1274 r
= sd_bus_message_enter_container(message
, 'a', "(st)");
1278 while ((r
= sd_bus_message_read(message
, "(st)", &path
, &u64
)) > 0) {
1280 if (!path_is_normalized(path
))
1281 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path '%s' specified in %s= is not normalized.", name
, path
);
1283 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1284 CGroupBlockIODeviceBandwidth
*a
= NULL
, *b
;
1286 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
1287 if (path_equal(path
, b
->path
)) {
1294 a
= new0(CGroupBlockIODeviceBandwidth
, 1);
1298 a
->rbps
= CGROUP_LIMIT_MAX
;
1299 a
->wbps
= CGROUP_LIMIT_MAX
;
1300 a
->path
= strdup(path
);
1306 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, a
);
1320 r
= sd_bus_message_exit_container(message
);
1324 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1325 CGroupBlockIODeviceBandwidth
*a
;
1326 _cleanup_free_
char *buf
= NULL
;
1327 _cleanup_fclose_
FILE *f
= NULL
;
1331 LIST_FOREACH(device_bandwidths
, a
, c
->blockio_device_bandwidths
) {
1333 a
->rbps
= CGROUP_LIMIT_MAX
;
1335 a
->wbps
= CGROUP_LIMIT_MAX
;
1339 unit_invalidate_cgroup(u
, CGROUP_MASK_BLKIO
);
1341 f
= open_memstream_unlocked(&buf
, &size
);
1346 fputs("BlockIOReadBandwidth=\n", f
);
1347 LIST_FOREACH(device_bandwidths
, a
, c
->blockio_device_bandwidths
)
1348 if (a
->rbps
!= CGROUP_LIMIT_MAX
)
1349 fprintf(f
, "BlockIOReadBandwidth=%s %" PRIu64
"\n", a
->path
, a
->rbps
);
1351 fputs("BlockIOWriteBandwidth=\n", f
);
1352 LIST_FOREACH(device_bandwidths
, a
, c
->blockio_device_bandwidths
)
1353 if (a
->wbps
!= CGROUP_LIMIT_MAX
)
1354 fprintf(f
, "BlockIOWriteBandwidth=%s %" PRIu64
"\n", a
->path
, a
->wbps
);
1357 r
= fflush_and_check(f
);
1361 unit_write_setting(u
, flags
, name
, buf
);
1366 } else if (streq(name
, "BlockIODeviceWeight")) {
1371 r
= sd_bus_message_enter_container(message
, 'a', "(st)");
1375 while ((r
= sd_bus_message_read(message
, "(st)", &path
, &weight
)) > 0) {
1377 if (!path_is_normalized(path
))
1378 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path '%s' specified in %s= is not normalized.", name
, path
);
1380 if (!CGROUP_BLKIO_WEIGHT_IS_OK(weight
) || weight
== CGROUP_BLKIO_WEIGHT_INVALID
)
1381 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "BlockIODeviceWeight= out of range");
1383 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1384 CGroupBlockIODeviceWeight
*a
= NULL
, *b
;
1386 LIST_FOREACH(device_weights
, b
, c
->blockio_device_weights
) {
1387 if (path_equal(b
->path
, path
)) {
1394 a
= new0(CGroupBlockIODeviceWeight
, 1);
1398 a
->path
= strdup(path
);
1403 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, a
);
1412 r
= sd_bus_message_exit_container(message
);
1416 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1417 _cleanup_free_
char *buf
= NULL
;
1418 _cleanup_fclose_
FILE *f
= NULL
;
1419 CGroupBlockIODeviceWeight
*a
;
1423 while (c
->blockio_device_weights
)
1424 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
1427 unit_invalidate_cgroup(u
, CGROUP_MASK_BLKIO
);
1429 f
= open_memstream_unlocked(&buf
, &size
);
1433 fputs("BlockIODeviceWeight=\n", f
);
1434 LIST_FOREACH(device_weights
, a
, c
->blockio_device_weights
)
1435 fprintf(f
, "BlockIODeviceWeight=%s %" PRIu64
"\n", a
->path
, a
->weight
);
1437 r
= fflush_and_check(f
);
1441 unit_write_setting(u
, flags
, name
, buf
);
1446 } else if (streq(name
, "DevicePolicy")) {
1448 CGroupDevicePolicy p
;
1450 r
= sd_bus_message_read(message
, "s", &policy
);
1454 p
= cgroup_device_policy_from_string(policy
);
1458 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1459 c
->device_policy
= p
;
1460 unit_invalidate_cgroup(u
, CGROUP_MASK_DEVICES
);
1461 unit_write_settingf(u
, flags
, name
, "DevicePolicy=%s", policy
);
1466 } else if (streq(name
, "DeviceAllow")) {
1467 const char *path
, *rwm
;
1470 r
= sd_bus_message_enter_container(message
, 'a', "(ss)");
1474 while ((r
= sd_bus_message_read(message
, "(ss)", &path
, &rwm
)) > 0) {
1476 if (!valid_device_allow_pattern(path
) || strpbrk(path
, WHITESPACE
))
1477 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "DeviceAllow= requires device node or pattern");
1481 else if (!in_charset(rwm
, "rwm"))
1482 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "DeviceAllow= requires combination of rwm flags");
1484 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1485 CGroupDeviceAllow
*a
= NULL
, *b
;
1487 LIST_FOREACH(device_allow
, b
, c
->device_allow
) {
1488 if (path_equal(b
->path
, path
)) {
1495 a
= new0(CGroupDeviceAllow
, 1);
1499 a
->path
= strdup(path
);
1505 LIST_PREPEND(device_allow
, c
->device_allow
, a
);
1508 a
->r
= strchr(rwm
, 'r');
1509 a
->w
= strchr(rwm
, 'w');
1510 a
->m
= strchr(rwm
, 'm');
1518 r
= sd_bus_message_exit_container(message
);
1522 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1523 _cleanup_free_
char *buf
= NULL
;
1524 _cleanup_fclose_
FILE *f
= NULL
;
1525 CGroupDeviceAllow
*a
;
1529 while (c
->device_allow
)
1530 cgroup_context_free_device_allow(c
, c
->device_allow
);
1533 unit_invalidate_cgroup(u
, CGROUP_MASK_DEVICES
);
1535 f
= open_memstream_unlocked(&buf
, &size
);
1539 fputs("DeviceAllow=\n", f
);
1540 LIST_FOREACH(device_allow
, a
, c
->device_allow
)
1541 fprintf(f
, "DeviceAllow=%s %s%s%s\n", a
->path
, a
->r
? "r" : "", a
->w
? "w" : "", a
->m
? "m" : "");
1543 r
= fflush_and_check(f
);
1546 unit_write_setting(u
, flags
, name
, buf
);
1551 } else if (streq(name
, "IPAccounting")) {
1554 r
= sd_bus_message_read(message
, "b", &b
);
1558 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1559 c
->ip_accounting
= b
;
1561 unit_invalidate_cgroup_bpf(u
);
1562 unit_write_settingf(u
, flags
, name
, "IPAccounting=%s", yes_no(b
));
1567 } else if (STR_IN_SET(name
, "IPAddressAllow", "IPAddressDeny")) {
1568 IPAddressAccessItem
**list
;
1571 list
= streq(name
, "IPAddressAllow") ? &c
->ip_address_allow
: &c
->ip_address_deny
;
1573 r
= sd_bus_message_enter_container(message
, 'a', "(iayu)");
1583 r
= sd_bus_message_enter_container(message
, 'r', "iayu");
1589 r
= sd_bus_message_read(message
, "i", &family
);
1593 if (!IN_SET(family
, AF_INET
, AF_INET6
))
1594 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= expects IPv4 or IPv6 addresses only.", name
);
1596 r
= sd_bus_message_read_array(message
, 'y', &ap
, &an
);
1600 if (an
!= FAMILY_ADDRESS_SIZE(family
))
1601 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "IP address has wrong size for family (%s, expected %zu, got %zu)",
1602 af_to_name(family
), FAMILY_ADDRESS_SIZE(family
), an
);
1604 r
= sd_bus_message_read(message
, "u", &prefixlen
);
1608 if (prefixlen
> FAMILY_ADDRESS_SIZE(family
)*8)
1609 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Prefix length %" PRIu32
" too large for address family %s.", prefixlen
, af_to_name(family
));
1611 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1612 IPAddressAccessItem
*item
;
1614 item
= new0(IPAddressAccessItem
, 1);
1618 item
->family
= family
;
1619 item
->prefixlen
= prefixlen
;
1620 memcpy(&item
->address
, ap
, an
);
1622 LIST_PREPEND(items
, *list
, item
);
1625 r
= sd_bus_message_exit_container(message
);
1632 r
= sd_bus_message_exit_container(message
);
1636 *list
= ip_address_access_reduce(*list
);
1638 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1639 _cleanup_free_
char *buf
= NULL
;
1640 _cleanup_fclose_
FILE *f
= NULL
;
1641 IPAddressAccessItem
*item
;
1645 *list
= ip_address_access_free_all(*list
);
1647 unit_invalidate_cgroup_bpf(u
);
1648 f
= open_memstream_unlocked(&buf
, &size
);
1655 LIST_FOREACH(items
, item
, *list
) {
1656 char buffer
[CONST_MAX(INET_ADDRSTRLEN
, INET6_ADDRSTRLEN
)];
1659 if (!inet_ntop(item
->family
, &item
->address
, buffer
, sizeof(buffer
)))
1660 return errno_or_else(EINVAL
);
1662 fprintf(f
, "%s=%s/%u\n", name
, buffer
, item
->prefixlen
);
1665 r
= fflush_and_check(f
);
1669 unit_write_setting(u
, flags
, name
, buf
);
1675 if (STR_IN_SET(name
, "ManagedOOMSwap", "ManagedOOMMemoryPressure")) {
1676 ManagedOOMMode
*cgroup_mode
= streq(name
, "ManagedOOMSwap") ? &c
->moom_swap
: &c
->moom_mem_pressure
;
1680 if (!UNIT_VTABLE(u
)->can_set_managed_oom
)
1681 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Cannot set %s for this unit type", name
);
1683 r
= sd_bus_message_read(message
, "s", &mode
);
1687 m
= managed_oom_mode_from_string(mode
);
1691 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1693 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, mode
);
1696 (void) manager_varlink_send_managed_oom_update(u
);
1700 if (streq(name
, "ManagedOOMMemoryPressureLimitPercent")) {
1701 if (!UNIT_VTABLE(u
)->can_set_managed_oom
)
1702 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Cannot set %s for this unit type", name
);
1704 r
= bus_set_transient_percent(u
, name
, &c
->moom_mem_pressure_limit
, message
, flags
, error
);
1708 if (c
->moom_mem_pressure
== MANAGED_OOM_KILL
)
1709 (void) manager_varlink_send_managed_oom_update(u
);
1714 if (streq(name
, "DisableControllers") || (u
->transient
&& u
->load_state
== UNIT_STUB
))
1715 return bus_cgroup_set_transient_property(u
, c
, name
, message
, flags
, error
);