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
;
40 r
= sd_bus_message_open_container(reply
, 'a', "s");
44 for (CGroupController ctrl
= 0; ctrl
< _CGROUP_CONTROLLER_MAX
; ctrl
++) {
45 if ((*mask
& CGROUP_CONTROLLER_TO_MASK(ctrl
)) == 0)
48 r
= sd_bus_message_append(reply
, "s", cgroup_controller_to_string(ctrl
));
53 return sd_bus_message_close_container(reply
);
56 static int property_get_delegate_controllers(
59 const char *interface
,
61 sd_bus_message
*reply
,
63 sd_bus_error
*error
) {
65 CGroupContext
*c
= userdata
;
72 return sd_bus_message_append(reply
, "as", 0);
74 return property_get_cgroup_mask(bus
, path
, interface
, property
, reply
, &c
->delegate_controllers
, error
);
77 static int property_get_cpuset(
80 const char *interface
,
82 sd_bus_message
*reply
,
84 sd_bus_error
*error
) {
86 CPUSet
*cpus
= userdata
;
87 _cleanup_free_
uint8_t *array
= NULL
;
94 (void) cpu_set_to_dbus(cpus
, &array
, &allocated
);
95 return sd_bus_message_append_array(reply
, 'y', array
, allocated
);
98 static int property_get_io_device_weight(
101 const char *interface
,
102 const char *property
,
103 sd_bus_message
*reply
,
105 sd_bus_error
*error
) {
107 CGroupContext
*c
= userdata
;
108 CGroupIODeviceWeight
*w
;
115 r
= sd_bus_message_open_container(reply
, 'a', "(st)");
119 LIST_FOREACH(device_weights
, w
, c
->io_device_weights
) {
120 r
= sd_bus_message_append(reply
, "(st)", w
->path
, w
->weight
);
125 return sd_bus_message_close_container(reply
);
128 static int property_get_io_device_limits(
131 const char *interface
,
132 const char *property
,
133 sd_bus_message
*reply
,
135 sd_bus_error
*error
) {
137 CGroupContext
*c
= userdata
;
138 CGroupIODeviceLimit
*l
;
145 r
= sd_bus_message_open_container(reply
, 'a', "(st)");
149 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
) {
150 CGroupIOLimitType type
;
152 type
= cgroup_io_limit_type_from_string(property
);
153 if (type
< 0 || l
->limits
[type
] == cgroup_io_limit_defaults
[type
])
156 r
= sd_bus_message_append(reply
, "(st)", l
->path
, l
->limits
[type
]);
161 return sd_bus_message_close_container(reply
);
164 static int property_get_io_device_latency(
167 const char *interface
,
168 const char *property
,
169 sd_bus_message
*reply
,
171 sd_bus_error
*error
) {
173 CGroupContext
*c
= userdata
;
174 CGroupIODeviceLatency
*l
;
181 r
= sd_bus_message_open_container(reply
, 'a', "(st)");
185 LIST_FOREACH(device_latencies
, l
, c
->io_device_latencies
) {
186 r
= sd_bus_message_append(reply
, "(st)", l
->path
, l
->target_usec
);
191 return sd_bus_message_close_container(reply
);
194 static int property_get_blockio_device_weight(
197 const char *interface
,
198 const char *property
,
199 sd_bus_message
*reply
,
201 sd_bus_error
*error
) {
203 CGroupContext
*c
= userdata
;
204 CGroupBlockIODeviceWeight
*w
;
211 r
= sd_bus_message_open_container(reply
, 'a', "(st)");
215 LIST_FOREACH(device_weights
, w
, c
->blockio_device_weights
) {
216 r
= sd_bus_message_append(reply
, "(st)", w
->path
, w
->weight
);
221 return sd_bus_message_close_container(reply
);
224 static int property_get_blockio_device_bandwidths(
227 const char *interface
,
228 const char *property
,
229 sd_bus_message
*reply
,
231 sd_bus_error
*error
) {
233 CGroupContext
*c
= userdata
;
234 CGroupBlockIODeviceBandwidth
*b
;
241 r
= sd_bus_message_open_container(reply
, 'a', "(st)");
245 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
248 if (streq(property
, "BlockIOReadBandwidth"))
253 if (v
== CGROUP_LIMIT_MAX
)
256 r
= sd_bus_message_append(reply
, "(st)", b
->path
, v
);
261 return sd_bus_message_close_container(reply
);
264 static int property_get_device_allow(
267 const char *interface
,
268 const char *property
,
269 sd_bus_message
*reply
,
271 sd_bus_error
*error
) {
273 CGroupContext
*c
= userdata
;
274 CGroupDeviceAllow
*a
;
281 r
= sd_bus_message_open_container(reply
, 'a', "(ss)");
285 LIST_FOREACH(device_allow
, a
, c
->device_allow
) {
298 r
= sd_bus_message_append(reply
, "(ss)", a
->path
, rwm
);
303 return sd_bus_message_close_container(reply
);
306 static int property_get_ip_address_access(
309 const char *interface
,
310 const char *property
,
311 sd_bus_message
*reply
,
313 sd_bus_error
*error
) {
315 IPAddressAccessItem
** items
= userdata
, *i
;
318 r
= sd_bus_message_open_container(reply
, 'a', "(iayu)");
322 LIST_FOREACH(items
, i
, *items
) {
324 r
= sd_bus_message_open_container(reply
, 'r', "iayu");
328 r
= sd_bus_message_append(reply
, "i", i
->family
);
332 r
= sd_bus_message_append_array(reply
, 'y', &i
->address
, FAMILY_ADDRESS_SIZE(i
->family
));
336 r
= sd_bus_message_append(reply
, "u", (uint32_t) i
->prefixlen
);
340 r
= sd_bus_message_close_container(reply
);
345 return sd_bus_message_close_container(reply
);
348 const sd_bus_vtable bus_cgroup_vtable
[] = {
349 SD_BUS_VTABLE_START(0),
350 SD_BUS_PROPERTY("Delegate", "b", bus_property_get_bool
, offsetof(CGroupContext
, delegate
), 0),
351 SD_BUS_PROPERTY("DelegateControllers", "as", property_get_delegate_controllers
, 0, 0),
352 SD_BUS_PROPERTY("CPUAccounting", "b", bus_property_get_bool
, offsetof(CGroupContext
, cpu_accounting
), 0),
353 SD_BUS_PROPERTY("CPUWeight", "t", NULL
, offsetof(CGroupContext
, cpu_weight
), 0),
354 SD_BUS_PROPERTY("StartupCPUWeight", "t", NULL
, offsetof(CGroupContext
, startup_cpu_weight
), 0),
355 SD_BUS_PROPERTY("CPUShares", "t", NULL
, offsetof(CGroupContext
, cpu_shares
), 0),
356 SD_BUS_PROPERTY("StartupCPUShares", "t", NULL
, offsetof(CGroupContext
, startup_cpu_shares
), 0),
357 SD_BUS_PROPERTY("CPUQuotaPerSecUSec", "t", bus_property_get_usec
, offsetof(CGroupContext
, cpu_quota_per_sec_usec
), 0),
358 SD_BUS_PROPERTY("CPUQuotaPeriodUSec", "t", bus_property_get_usec
, offsetof(CGroupContext
, cpu_quota_period_usec
), 0),
359 SD_BUS_PROPERTY("AllowedCPUs", "ay", property_get_cpuset
, offsetof(CGroupContext
, cpuset_cpus
), 0),
360 SD_BUS_PROPERTY("AllowedMemoryNodes", "ay", property_get_cpuset
, offsetof(CGroupContext
, cpuset_mems
), 0),
361 SD_BUS_PROPERTY("IOAccounting", "b", bus_property_get_bool
, offsetof(CGroupContext
, io_accounting
), 0),
362 SD_BUS_PROPERTY("IOWeight", "t", NULL
, offsetof(CGroupContext
, io_weight
), 0),
363 SD_BUS_PROPERTY("StartupIOWeight", "t", NULL
, offsetof(CGroupContext
, startup_io_weight
), 0),
364 SD_BUS_PROPERTY("IODeviceWeight", "a(st)", property_get_io_device_weight
, 0, 0),
365 SD_BUS_PROPERTY("IOReadBandwidthMax", "a(st)", property_get_io_device_limits
, 0, 0),
366 SD_BUS_PROPERTY("IOWriteBandwidthMax", "a(st)", property_get_io_device_limits
, 0, 0),
367 SD_BUS_PROPERTY("IOReadIOPSMax", "a(st)", property_get_io_device_limits
, 0, 0),
368 SD_BUS_PROPERTY("IOWriteIOPSMax", "a(st)", property_get_io_device_limits
, 0, 0),
369 SD_BUS_PROPERTY("IODeviceLatencyTargetUSec", "a(st)", property_get_io_device_latency
, 0, 0),
370 SD_BUS_PROPERTY("BlockIOAccounting", "b", bus_property_get_bool
, offsetof(CGroupContext
, blockio_accounting
), 0),
371 SD_BUS_PROPERTY("BlockIOWeight", "t", NULL
, offsetof(CGroupContext
, blockio_weight
), 0),
372 SD_BUS_PROPERTY("StartupBlockIOWeight", "t", NULL
, offsetof(CGroupContext
, startup_blockio_weight
), 0),
373 SD_BUS_PROPERTY("BlockIODeviceWeight", "a(st)", property_get_blockio_device_weight
, 0, 0),
374 SD_BUS_PROPERTY("BlockIOReadBandwidth", "a(st)", property_get_blockio_device_bandwidths
, 0, 0),
375 SD_BUS_PROPERTY("BlockIOWriteBandwidth", "a(st)", property_get_blockio_device_bandwidths
, 0, 0),
376 SD_BUS_PROPERTY("MemoryAccounting", "b", bus_property_get_bool
, offsetof(CGroupContext
, memory_accounting
), 0),
377 SD_BUS_PROPERTY("DefaultMemoryLow", "t", NULL
, offsetof(CGroupContext
, default_memory_low
), 0),
378 SD_BUS_PROPERTY("DefaultMemoryMin", "t", NULL
, offsetof(CGroupContext
, default_memory_min
), 0),
379 SD_BUS_PROPERTY("MemoryMin", "t", NULL
, offsetof(CGroupContext
, memory_min
), 0),
380 SD_BUS_PROPERTY("MemoryLow", "t", NULL
, offsetof(CGroupContext
, memory_low
), 0),
381 SD_BUS_PROPERTY("MemoryHigh", "t", NULL
, offsetof(CGroupContext
, memory_high
), 0),
382 SD_BUS_PROPERTY("MemoryMax", "t", NULL
, offsetof(CGroupContext
, memory_max
), 0),
383 SD_BUS_PROPERTY("MemorySwapMax", "t", NULL
, offsetof(CGroupContext
, memory_swap_max
), 0),
384 SD_BUS_PROPERTY("MemoryLimit", "t", NULL
, offsetof(CGroupContext
, memory_limit
), 0),
385 SD_BUS_PROPERTY("DevicePolicy", "s", property_get_cgroup_device_policy
, offsetof(CGroupContext
, device_policy
), 0),
386 SD_BUS_PROPERTY("DeviceAllow", "a(ss)", property_get_device_allow
, 0, 0),
387 SD_BUS_PROPERTY("TasksAccounting", "b", bus_property_get_bool
, offsetof(CGroupContext
, tasks_accounting
), 0),
388 SD_BUS_PROPERTY("TasksMax", "t", bus_property_get_tasks_max
, offsetof(CGroupContext
, tasks_max
), 0),
389 SD_BUS_PROPERTY("IPAccounting", "b", bus_property_get_bool
, offsetof(CGroupContext
, ip_accounting
), 0),
390 SD_BUS_PROPERTY("IPAddressAllow", "a(iayu)", property_get_ip_address_access
, offsetof(CGroupContext
, ip_address_allow
), 0),
391 SD_BUS_PROPERTY("IPAddressDeny", "a(iayu)", property_get_ip_address_access
, offsetof(CGroupContext
, ip_address_deny
), 0),
392 SD_BUS_PROPERTY("IPIngressFilterPath", "as", NULL
, offsetof(CGroupContext
, ip_filters_ingress
), 0),
393 SD_BUS_PROPERTY("IPEgressFilterPath", "as", NULL
, offsetof(CGroupContext
, ip_filters_egress
), 0),
394 SD_BUS_PROPERTY("DisableControllers", "as", property_get_cgroup_mask
, offsetof(CGroupContext
, disable_controllers
), 0),
395 SD_BUS_PROPERTY("ManagedOOMSwap", "s", property_get_managed_oom_mode
, offsetof(CGroupContext
, moom_swap
), 0),
396 SD_BUS_PROPERTY("ManagedOOMMemoryPressure", "s", property_get_managed_oom_mode
, offsetof(CGroupContext
, moom_mem_pressure
), 0),
397 SD_BUS_PROPERTY("ManagedOOMMemoryPressureLimitPermyriad", "u", NULL
, offsetof(CGroupContext
, moom_mem_pressure_limit_permyriad
), 0),
401 static int bus_cgroup_set_transient_property(
405 sd_bus_message
*message
,
406 UnitWriteFlags flags
,
407 sd_bus_error
*error
) {
416 flags
|= UNIT_PRIVATE
;
418 if (streq(name
, "Delegate")) {
421 if (!UNIT_VTABLE(u
)->can_delegate
)
422 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Delegation not available for unit type");
424 r
= sd_bus_message_read(message
, "b", &b
);
428 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
430 c
->delegate_controllers
= b
? _CGROUP_MASK_ALL
: 0;
432 unit_write_settingf(u
, flags
, name
, "Delegate=%s", yes_no(b
));
437 } else if (STR_IN_SET(name
, "DelegateControllers", "DisableControllers")) {
440 if (streq(name
, "DelegateControllers") && !UNIT_VTABLE(u
)->can_delegate
)
441 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Delegation not available for unit type");
443 r
= sd_bus_message_enter_container(message
, 'a', "s");
451 r
= sd_bus_message_read(message
, "s", &t
);
457 cc
= cgroup_controller_from_string(t
);
459 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Unknown cgroup controller '%s'", t
);
461 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
464 r
= sd_bus_message_exit_container(message
);
468 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
469 _cleanup_free_
char *t
= NULL
;
471 r
= cg_mask_to_string(mask
, &t
);
475 if (streq(name
, "DelegateControllers")) {
479 c
->delegate_controllers
= 0;
481 c
->delegate_controllers
|= mask
;
483 unit_write_settingf(u
, flags
, name
, "Delegate=%s", strempty(t
));
485 } else if (streq(name
, "DisableControllers")) {
488 c
->disable_controllers
= 0;
490 c
->disable_controllers
|= mask
;
492 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, strempty(t
));
497 } else if (STR_IN_SET(name
, "IPIngressFilterPath", "IPEgressFilterPath")) {
501 filters
= streq(name
, "IPIngressFilterPath") ? &c
->ip_filters_ingress
: &c
->ip_filters_egress
;
502 r
= sd_bus_message_enter_container(message
, 'a', "s");
509 r
= sd_bus_message_read(message
, "s", &path
);
515 if (!path_is_normalized(path
) || !path_is_absolute(path
))
516 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= expects a normalized absolute path.", name
);
518 if (!UNIT_WRITE_FLAGS_NOOP(flags
) && !strv_contains(*filters
, path
)) {
519 r
= strv_extend(filters
, path
);
525 r
= sd_bus_message_exit_container(message
);
529 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
530 _cleanup_free_
char *buf
= NULL
;
531 _cleanup_fclose_
FILE *f
= NULL
;
536 *filters
= strv_free(*filters
);
538 unit_invalidate_cgroup_bpf(u
);
539 f
= open_memstream_unlocked(&buf
, &size
);
546 STRV_FOREACH(entry
, *filters
)
547 fprintf(f
, "%s=%s\n", name
, *entry
);
549 r
= fflush_and_check(f
);
553 unit_write_setting(u
, flags
, name
, buf
);
556 r
= bpf_firewall_supported();
559 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
560 static bool warned
= false;
562 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
563 "Transient unit %s configures an IP firewall with BPF, but the local system does not support BPF/cgroup firewalling with multiple filters.\n"
564 "Starting this unit will fail! (This warning is only shown for the first started transient unit using IP firewalling.)", u
->id
);
576 static int bus_cgroup_set_boolean(
581 sd_bus_message
*message
,
582 UnitWriteFlags flags
,
583 sd_bus_error
*error
) {
589 r
= sd_bus_message_read(message
, "b", &b
);
593 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
595 unit_invalidate_cgroup(u
, mask
);
596 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, yes_no(b
));
602 #define BUS_DEFINE_SET_CGROUP_WEIGHT(function, mask, check, val) \
603 static int bus_cgroup_set_##function( \
607 sd_bus_message *message, \
608 UnitWriteFlags flags, \
609 sd_bus_error *error) { \
616 r = sd_bus_message_read(message, "t", &v); \
621 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, \
622 "Value specified in %s is out of range", name); \
624 if (!UNIT_WRITE_FLAGS_NOOP(flags)) { \
626 unit_invalidate_cgroup(u, mask); \
629 unit_write_settingf(u, flags, name, \
632 unit_write_settingf(u, flags, name, \
633 "%s=%" PRIu64, name, v); \
639 #define BUS_DEFINE_SET_CGROUP_LIMIT(function, mask, scale, minimum) \
640 static int bus_cgroup_set_##function( \
644 sd_bus_message *message, \
645 UnitWriteFlags flags, \
646 sd_bus_error *error) { \
653 r = sd_bus_message_read(message, "t", &v); \
658 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, \
659 "Value specified in %s is out of range", name); \
661 if (!UNIT_WRITE_FLAGS_NOOP(flags)) { \
663 unit_invalidate_cgroup(u, mask); \
665 if (v == CGROUP_LIMIT_MAX) \
666 unit_write_settingf(u, flags, name, \
667 "%s=infinity", name); \
669 unit_write_settingf(u, flags, name, \
670 "%s=%" PRIu64, name, v); \
675 static int bus_cgroup_set_##function##_scale( \
679 sd_bus_message *message, \
680 UnitWriteFlags flags, \
681 sd_bus_error *error) { \
689 r = sd_bus_message_read(message, "u", &raw); \
693 v = scale(raw, UINT32_MAX); \
694 if (v < minimum || v >= UINT64_MAX) \
695 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, \
696 "Value specified in %s is out of range", name); \
698 if (!UNIT_WRITE_FLAGS_NOOP(flags)) { \
700 unit_invalidate_cgroup(u, mask); \
702 /* Prepare to chop off suffix */ \
703 assert_se(endswith(name, "Scale")); \
705 uint32_t scaled = DIV_ROUND_UP((uint64_t) raw * 1000, (uint64_t) UINT32_MAX); \
706 unit_write_settingf(u, flags, name, "%.*s=%" PRIu32 ".%" PRIu32 "%%", \
707 (int)(strlen(name) - strlen("Scale")), name, \
708 scaled / 10, scaled % 10); \
714 DISABLE_WARNING_TYPE_LIMITS
;
715 BUS_DEFINE_SET_CGROUP_WEIGHT(cpu_weight
, CGROUP_MASK_CPU
, CGROUP_WEIGHT_IS_OK
, CGROUP_WEIGHT_INVALID
);
716 BUS_DEFINE_SET_CGROUP_WEIGHT(cpu_shares
, CGROUP_MASK_CPU
, CGROUP_CPU_SHARES_IS_OK
, CGROUP_CPU_SHARES_INVALID
);
717 BUS_DEFINE_SET_CGROUP_WEIGHT(io_weight
, CGROUP_MASK_IO
, CGROUP_WEIGHT_IS_OK
, CGROUP_WEIGHT_INVALID
);
718 BUS_DEFINE_SET_CGROUP_WEIGHT(blockio_weight
, CGROUP_MASK_BLKIO
, CGROUP_BLKIO_WEIGHT_IS_OK
, CGROUP_BLKIO_WEIGHT_INVALID
);
719 BUS_DEFINE_SET_CGROUP_LIMIT(memory
, CGROUP_MASK_MEMORY
, physical_memory_scale
, 1);
720 BUS_DEFINE_SET_CGROUP_LIMIT(memory_protection
, CGROUP_MASK_MEMORY
, physical_memory_scale
, 0);
721 BUS_DEFINE_SET_CGROUP_LIMIT(swap
, CGROUP_MASK_MEMORY
, physical_memory_scale
, 0);
724 static int bus_cgroup_set_tasks_max(
728 sd_bus_message
*message
,
729 UnitWriteFlags flags
,
730 sd_bus_error
*error
) {
737 r
= sd_bus_message_read(message
, "t", &v
);
742 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
,
743 "Value specified in %s is out of range", name
);
745 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
746 *p
= (TasksMax
) { .value
= v
, .scale
= 0 }; /* When .scale==0, .value is the absolute value */
747 unit_invalidate_cgroup(u
, CGROUP_MASK_PIDS
);
749 if (v
== CGROUP_LIMIT_MAX
)
750 unit_write_settingf(u
, flags
, name
,
751 "%s=infinity", name
);
753 unit_write_settingf(u
, flags
, name
,
754 "%s=%" PRIu64
, name
, v
);
760 static int bus_cgroup_set_tasks_max_scale(
764 sd_bus_message
*message
,
765 UnitWriteFlags flags
,
766 sd_bus_error
*error
) {
773 r
= sd_bus_message_read(message
, "u", &v
);
777 if (v
< 1 || v
>= UINT32_MAX
)
778 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
,
779 "Value specified in %s is out of range", name
);
781 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
782 *p
= (TasksMax
) { v
, UINT32_MAX
}; /* .scale is not 0, so this is interpreted as v/UINT32_MAX. */
783 unit_invalidate_cgroup(u
, CGROUP_MASK_PIDS
);
785 uint32_t scaled
= DIV_ROUND_UP((uint64_t) v
* 100U, (uint64_t) UINT32_MAX
);
786 unit_write_settingf(u
, flags
, name
, "%s=%" PRIu32
".%" PRIu32
"%%", "TasksMax",
787 scaled
/ 10, scaled
% 10);
793 int bus_cgroup_set_property(
797 sd_bus_message
*message
,
798 UnitWriteFlags flags
,
799 sd_bus_error
*error
) {
801 CGroupIOLimitType iol_type
;
809 flags
|= UNIT_PRIVATE
;
811 if (streq(name
, "CPUAccounting"))
812 return bus_cgroup_set_boolean(u
, name
, &c
->cpu_accounting
, get_cpu_accounting_mask(), message
, flags
, error
);
814 if (streq(name
, "CPUWeight"))
815 return bus_cgroup_set_cpu_weight(u
, name
, &c
->cpu_weight
, message
, flags
, error
);
817 if (streq(name
, "StartupCPUWeight"))
818 return bus_cgroup_set_cpu_weight(u
, name
, &c
->startup_cpu_weight
, message
, flags
, error
);
820 if (streq(name
, "CPUShares"))
821 return bus_cgroup_set_cpu_shares(u
, name
, &c
->cpu_shares
, message
, flags
, error
);
823 if (streq(name
, "StartupCPUShares"))
824 return bus_cgroup_set_cpu_shares(u
, name
, &c
->startup_cpu_shares
, message
, flags
, error
);
826 if (streq(name
, "IOAccounting"))
827 return bus_cgroup_set_boolean(u
, name
, &c
->io_accounting
, CGROUP_MASK_IO
, message
, flags
, error
);
829 if (streq(name
, "IOWeight"))
830 return bus_cgroup_set_io_weight(u
, name
, &c
->io_weight
, message
, flags
, error
);
832 if (streq(name
, "StartupIOWeight"))
833 return bus_cgroup_set_io_weight(u
, name
, &c
->startup_io_weight
, message
, flags
, error
);
835 if (streq(name
, "BlockIOAccounting"))
836 return bus_cgroup_set_boolean(u
, name
, &c
->blockio_accounting
, CGROUP_MASK_BLKIO
, message
, flags
, error
);
838 if (streq(name
, "BlockIOWeight"))
839 return bus_cgroup_set_blockio_weight(u
, name
, &c
->blockio_weight
, message
, flags
, error
);
841 if (streq(name
, "StartupBlockIOWeight"))
842 return bus_cgroup_set_blockio_weight(u
, name
, &c
->startup_blockio_weight
, message
, flags
, error
);
844 if (streq(name
, "MemoryAccounting"))
845 return bus_cgroup_set_boolean(u
, name
, &c
->memory_accounting
, CGROUP_MASK_MEMORY
, message
, flags
, error
);
847 if (streq(name
, "MemoryMin")) {
848 r
= bus_cgroup_set_memory_protection(u
, name
, &c
->memory_min
, message
, flags
, error
);
850 c
->memory_min_set
= true;
854 if (streq(name
, "MemoryLow")) {
855 r
= bus_cgroup_set_memory_protection(u
, name
, &c
->memory_low
, message
, flags
, error
);
857 c
->memory_low_set
= true;
861 if (streq(name
, "DefaultMemoryMin")) {
862 r
= bus_cgroup_set_memory_protection(u
, name
, &c
->default_memory_min
, message
, flags
, error
);
864 c
->default_memory_min_set
= true;
868 if (streq(name
, "DefaultMemoryLow")) {
869 r
= bus_cgroup_set_memory_protection(u
, name
, &c
->default_memory_low
, message
, flags
, error
);
871 c
->default_memory_low_set
= true;
875 if (streq(name
, "MemoryHigh"))
876 return bus_cgroup_set_memory(u
, name
, &c
->memory_high
, message
, flags
, error
);
878 if (streq(name
, "MemorySwapMax"))
879 return bus_cgroup_set_swap(u
, name
, &c
->memory_swap_max
, message
, flags
, error
);
881 if (streq(name
, "MemoryMax"))
882 return bus_cgroup_set_memory(u
, name
, &c
->memory_max
, message
, flags
, error
);
884 if (streq(name
, "MemoryLimit"))
885 return bus_cgroup_set_memory(u
, name
, &c
->memory_limit
, message
, flags
, error
);
887 if (streq(name
, "MemoryMinScale")) {
888 r
= bus_cgroup_set_memory_protection_scale(u
, name
, &c
->memory_min
, message
, flags
, error
);
890 c
->memory_min_set
= true;
894 if (streq(name
, "MemoryLowScale")) {
895 r
= bus_cgroup_set_memory_protection_scale(u
, name
, &c
->memory_low
, message
, flags
, error
);
897 c
->memory_low_set
= true;
901 if (streq(name
, "DefaultMemoryMinScale")) {
902 r
= bus_cgroup_set_memory_protection_scale(u
, name
, &c
->default_memory_min
, message
, flags
, error
);
904 c
->default_memory_min_set
= true;
908 if (streq(name
, "DefaultMemoryLowScale")) {
909 r
= bus_cgroup_set_memory_protection_scale(u
, name
, &c
->default_memory_low
, message
, flags
, error
);
911 c
->default_memory_low_set
= true;
915 if (streq(name
, "MemoryHighScale"))
916 return bus_cgroup_set_memory_scale(u
, name
, &c
->memory_high
, message
, flags
, error
);
918 if (streq(name
, "MemorySwapMaxScale"))
919 return bus_cgroup_set_swap_scale(u
, name
, &c
->memory_swap_max
, message
, flags
, error
);
921 if (streq(name
, "MemoryMaxScale"))
922 return bus_cgroup_set_memory_scale(u
, name
, &c
->memory_max
, message
, flags
, error
);
924 if (streq(name
, "MemoryLimitScale"))
925 return bus_cgroup_set_memory_scale(u
, name
, &c
->memory_limit
, message
, flags
, error
);
927 if (streq(name
, "TasksAccounting"))
928 return bus_cgroup_set_boolean(u
, name
, &c
->tasks_accounting
, CGROUP_MASK_PIDS
, message
, flags
, error
);
930 if (streq(name
, "TasksMax"))
931 return bus_cgroup_set_tasks_max(u
, name
, &c
->tasks_max
, message
, flags
, error
);
933 if (streq(name
, "TasksMaxScale"))
934 return bus_cgroup_set_tasks_max_scale(u
, name
, &c
->tasks_max
, message
, flags
, error
);
936 if (streq(name
, "CPUQuotaPerSecUSec")) {
939 r
= sd_bus_message_read(message
, "t", &u64
);
944 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "CPUQuotaPerSecUSec= value out of range");
946 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
947 c
->cpu_quota_per_sec_usec
= u64
;
948 u
->warned_clamping_cpu_quota_period
= false;
949 unit_invalidate_cgroup(u
, CGROUP_MASK_CPU
);
951 if (c
->cpu_quota_per_sec_usec
== USEC_INFINITY
)
952 unit_write_setting(u
, flags
, "CPUQuota", "CPUQuota=");
954 /* config_parse_cpu_quota() requires an integer, so truncating division is used on
956 unit_write_settingf(u
, flags
, "CPUQuota",
958 (double) (c
->cpu_quota_per_sec_usec
/ 10000));
963 } else if (streq(name
, "CPUQuotaPeriodUSec")) {
966 r
= sd_bus_message_read(message
, "t", &u64
);
970 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
971 c
->cpu_quota_period_usec
= u64
;
972 u
->warned_clamping_cpu_quota_period
= false;
973 unit_invalidate_cgroup(u
, CGROUP_MASK_CPU
);
974 if (c
->cpu_quota_period_usec
== USEC_INFINITY
)
975 unit_write_setting(u
, flags
, "CPUQuotaPeriodSec", "CPUQuotaPeriodSec=");
977 char v
[FORMAT_TIMESPAN_MAX
];
978 unit_write_settingf(u
, flags
, "CPUQuotaPeriodSec",
979 "CPUQuotaPeriodSec=%s",
980 format_timespan(v
, sizeof(v
), c
->cpu_quota_period_usec
, 1));
986 } else if (STR_IN_SET(name
, "AllowedCPUs", "AllowedMemoryNodes")) {
989 _cleanup_(cpu_set_reset
) CPUSet new_set
= {};
991 r
= sd_bus_message_read_array(message
, 'y', &a
, &n
);
995 r
= cpu_set_from_dbus(a
, n
, &new_set
);
999 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1000 _cleanup_free_
char *setstr
= NULL
;
1003 setstr
= cpu_set_to_range_string(&new_set
);
1007 if (streq(name
, "AllowedCPUs"))
1008 set
= &c
->cpuset_cpus
;
1010 set
= &c
->cpuset_mems
;
1014 new_set
= (CPUSet
) {};
1016 unit_invalidate_cgroup(u
, CGROUP_MASK_CPUSET
);
1017 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, setstr
);
1022 } else if ((iol_type
= cgroup_io_limit_type_from_string(name
)) >= 0) {
1027 r
= sd_bus_message_enter_container(message
, 'a', "(st)");
1031 while ((r
= sd_bus_message_read(message
, "(st)", &path
, &u64
)) > 0) {
1033 if (!path_is_normalized(path
))
1034 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path '%s' specified in %s= is not normalized.", name
, path
);
1036 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1037 CGroupIODeviceLimit
*a
= NULL
, *b
;
1039 LIST_FOREACH(device_limits
, b
, c
->io_device_limits
) {
1040 if (path_equal(path
, b
->path
)) {
1047 CGroupIOLimitType type
;
1049 a
= new0(CGroupIODeviceLimit
, 1);
1053 a
->path
= strdup(path
);
1059 for (type
= 0; type
< _CGROUP_IO_LIMIT_TYPE_MAX
; type
++)
1060 a
->limits
[type
] = cgroup_io_limit_defaults
[type
];
1062 LIST_PREPEND(device_limits
, c
->io_device_limits
, a
);
1065 a
->limits
[iol_type
] = u64
;
1073 r
= sd_bus_message_exit_container(message
);
1077 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1078 CGroupIODeviceLimit
*a
;
1079 _cleanup_free_
char *buf
= NULL
;
1080 _cleanup_fclose_
FILE *f
= NULL
;
1084 LIST_FOREACH(device_limits
, a
, c
->io_device_limits
)
1085 a
->limits
[iol_type
] = cgroup_io_limit_defaults
[iol_type
];
1088 unit_invalidate_cgroup(u
, CGROUP_MASK_IO
);
1090 f
= open_memstream_unlocked(&buf
, &size
);
1094 fprintf(f
, "%s=\n", name
);
1095 LIST_FOREACH(device_limits
, a
, c
->io_device_limits
)
1096 if (a
->limits
[iol_type
] != cgroup_io_limit_defaults
[iol_type
])
1097 fprintf(f
, "%s=%s %" PRIu64
"\n", name
, a
->path
, a
->limits
[iol_type
]);
1099 r
= fflush_and_check(f
);
1102 unit_write_setting(u
, flags
, name
, buf
);
1107 } else if (streq(name
, "IODeviceWeight")) {
1112 r
= sd_bus_message_enter_container(message
, 'a', "(st)");
1116 while ((r
= sd_bus_message_read(message
, "(st)", &path
, &weight
)) > 0) {
1118 if (!path_is_normalized(path
))
1119 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path '%s' specified in %s= is not normalized.", name
, path
);
1121 if (!CGROUP_WEIGHT_IS_OK(weight
) || weight
== CGROUP_WEIGHT_INVALID
)
1122 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "IODeviceWeight= value out of range");
1124 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1125 CGroupIODeviceWeight
*a
= NULL
, *b
;
1127 LIST_FOREACH(device_weights
, b
, c
->io_device_weights
) {
1128 if (path_equal(b
->path
, path
)) {
1135 a
= new0(CGroupIODeviceWeight
, 1);
1139 a
->path
= strdup(path
);
1144 LIST_PREPEND(device_weights
, c
->io_device_weights
, a
);
1153 r
= sd_bus_message_exit_container(message
);
1157 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1158 _cleanup_free_
char *buf
= NULL
;
1159 _cleanup_fclose_
FILE *f
= NULL
;
1160 CGroupIODeviceWeight
*a
;
1164 while (c
->io_device_weights
)
1165 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
1168 unit_invalidate_cgroup(u
, CGROUP_MASK_IO
);
1170 f
= open_memstream_unlocked(&buf
, &size
);
1174 fputs("IODeviceWeight=\n", f
);
1175 LIST_FOREACH(device_weights
, a
, c
->io_device_weights
)
1176 fprintf(f
, "IODeviceWeight=%s %" PRIu64
"\n", a
->path
, a
->weight
);
1178 r
= fflush_and_check(f
);
1181 unit_write_setting(u
, flags
, name
, buf
);
1186 } else if (streq(name
, "IODeviceLatencyTargetUSec")) {
1191 r
= sd_bus_message_enter_container(message
, 'a', "(st)");
1195 while ((r
= sd_bus_message_read(message
, "(st)", &path
, &target
)) > 0) {
1197 if (!path_is_normalized(path
))
1198 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path '%s' specified in %s= is not normalized.", name
, path
);
1200 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1201 CGroupIODeviceLatency
*a
= NULL
, *b
;
1203 LIST_FOREACH(device_latencies
, b
, c
->io_device_latencies
) {
1204 if (path_equal(b
->path
, path
)) {
1211 a
= new0(CGroupIODeviceLatency
, 1);
1215 a
->path
= strdup(path
);
1220 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, a
);
1223 a
->target_usec
= target
;
1229 r
= sd_bus_message_exit_container(message
);
1233 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1234 _cleanup_free_
char *buf
= NULL
;
1235 _cleanup_fclose_
FILE *f
= NULL
;
1236 char ts
[FORMAT_TIMESPAN_MAX
];
1237 CGroupIODeviceLatency
*a
;
1241 while (c
->io_device_latencies
)
1242 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
1245 unit_invalidate_cgroup(u
, CGROUP_MASK_IO
);
1247 f
= open_memstream_unlocked(&buf
, &size
);
1251 fputs("IODeviceLatencyTargetSec=\n", f
);
1252 LIST_FOREACH(device_latencies
, a
, c
->io_device_latencies
)
1253 fprintf(f
, "IODeviceLatencyTargetSec=%s %s\n",
1254 a
->path
, format_timespan(ts
, sizeof(ts
), a
->target_usec
, 1));
1256 r
= fflush_and_check(f
);
1259 unit_write_setting(u
, flags
, name
, buf
);
1264 } else if (STR_IN_SET(name
, "BlockIOReadBandwidth", "BlockIOWriteBandwidth")) {
1270 if (streq(name
, "BlockIOWriteBandwidth"))
1273 r
= sd_bus_message_enter_container(message
, 'a', "(st)");
1277 while ((r
= sd_bus_message_read(message
, "(st)", &path
, &u64
)) > 0) {
1279 if (!path_is_normalized(path
))
1280 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path '%s' specified in %s= is not normalized.", name
, path
);
1282 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1283 CGroupBlockIODeviceBandwidth
*a
= NULL
, *b
;
1285 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
1286 if (path_equal(path
, b
->path
)) {
1293 a
= new0(CGroupBlockIODeviceBandwidth
, 1);
1297 a
->rbps
= CGROUP_LIMIT_MAX
;
1298 a
->wbps
= CGROUP_LIMIT_MAX
;
1299 a
->path
= strdup(path
);
1305 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, a
);
1319 r
= sd_bus_message_exit_container(message
);
1323 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1324 CGroupBlockIODeviceBandwidth
*a
;
1325 _cleanup_free_
char *buf
= NULL
;
1326 _cleanup_fclose_
FILE *f
= NULL
;
1330 LIST_FOREACH(device_bandwidths
, a
, c
->blockio_device_bandwidths
) {
1332 a
->rbps
= CGROUP_LIMIT_MAX
;
1334 a
->wbps
= CGROUP_LIMIT_MAX
;
1338 unit_invalidate_cgroup(u
, CGROUP_MASK_BLKIO
);
1340 f
= open_memstream_unlocked(&buf
, &size
);
1345 fputs("BlockIOReadBandwidth=\n", f
);
1346 LIST_FOREACH(device_bandwidths
, a
, c
->blockio_device_bandwidths
)
1347 if (a
->rbps
!= CGROUP_LIMIT_MAX
)
1348 fprintf(f
, "BlockIOReadBandwidth=%s %" PRIu64
"\n", a
->path
, a
->rbps
);
1350 fputs("BlockIOWriteBandwidth=\n", f
);
1351 LIST_FOREACH(device_bandwidths
, a
, c
->blockio_device_bandwidths
)
1352 if (a
->wbps
!= CGROUP_LIMIT_MAX
)
1353 fprintf(f
, "BlockIOWriteBandwidth=%s %" PRIu64
"\n", a
->path
, a
->wbps
);
1356 r
= fflush_and_check(f
);
1360 unit_write_setting(u
, flags
, name
, buf
);
1365 } else if (streq(name
, "BlockIODeviceWeight")) {
1370 r
= sd_bus_message_enter_container(message
, 'a', "(st)");
1374 while ((r
= sd_bus_message_read(message
, "(st)", &path
, &weight
)) > 0) {
1376 if (!path_is_normalized(path
))
1377 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Path '%s' specified in %s= is not normalized.", name
, path
);
1379 if (!CGROUP_BLKIO_WEIGHT_IS_OK(weight
) || weight
== CGROUP_BLKIO_WEIGHT_INVALID
)
1380 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "BlockIODeviceWeight= out of range");
1382 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1383 CGroupBlockIODeviceWeight
*a
= NULL
, *b
;
1385 LIST_FOREACH(device_weights
, b
, c
->blockio_device_weights
) {
1386 if (path_equal(b
->path
, path
)) {
1393 a
= new0(CGroupBlockIODeviceWeight
, 1);
1397 a
->path
= strdup(path
);
1402 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, a
);
1411 r
= sd_bus_message_exit_container(message
);
1415 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1416 _cleanup_free_
char *buf
= NULL
;
1417 _cleanup_fclose_
FILE *f
= NULL
;
1418 CGroupBlockIODeviceWeight
*a
;
1422 while (c
->blockio_device_weights
)
1423 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
1426 unit_invalidate_cgroup(u
, CGROUP_MASK_BLKIO
);
1428 f
= open_memstream_unlocked(&buf
, &size
);
1432 fputs("BlockIODeviceWeight=\n", f
);
1433 LIST_FOREACH(device_weights
, a
, c
->blockio_device_weights
)
1434 fprintf(f
, "BlockIODeviceWeight=%s %" PRIu64
"\n", a
->path
, a
->weight
);
1436 r
= fflush_and_check(f
);
1440 unit_write_setting(u
, flags
, name
, buf
);
1445 } else if (streq(name
, "DevicePolicy")) {
1447 CGroupDevicePolicy p
;
1449 r
= sd_bus_message_read(message
, "s", &policy
);
1453 p
= cgroup_device_policy_from_string(policy
);
1457 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1458 c
->device_policy
= p
;
1459 unit_invalidate_cgroup(u
, CGROUP_MASK_DEVICES
);
1460 unit_write_settingf(u
, flags
, name
, "DevicePolicy=%s", policy
);
1465 } else if (streq(name
, "DeviceAllow")) {
1466 const char *path
, *rwm
;
1469 r
= sd_bus_message_enter_container(message
, 'a', "(ss)");
1473 while ((r
= sd_bus_message_read(message
, "(ss)", &path
, &rwm
)) > 0) {
1475 if (!valid_device_allow_pattern(path
) || strpbrk(path
, WHITESPACE
))
1476 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "DeviceAllow= requires device node or pattern");
1480 else if (!in_charset(rwm
, "rwm"))
1481 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "DeviceAllow= requires combination of rwm flags");
1483 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1484 CGroupDeviceAllow
*a
= NULL
, *b
;
1486 LIST_FOREACH(device_allow
, b
, c
->device_allow
) {
1487 if (path_equal(b
->path
, path
)) {
1494 a
= new0(CGroupDeviceAllow
, 1);
1498 a
->path
= strdup(path
);
1504 LIST_PREPEND(device_allow
, c
->device_allow
, a
);
1507 a
->r
= strchr(rwm
, 'r');
1508 a
->w
= strchr(rwm
, 'w');
1509 a
->m
= strchr(rwm
, 'm');
1517 r
= sd_bus_message_exit_container(message
);
1521 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1522 _cleanup_free_
char *buf
= NULL
;
1523 _cleanup_fclose_
FILE *f
= NULL
;
1524 CGroupDeviceAllow
*a
;
1528 while (c
->device_allow
)
1529 cgroup_context_free_device_allow(c
, c
->device_allow
);
1532 unit_invalidate_cgroup(u
, CGROUP_MASK_DEVICES
);
1534 f
= open_memstream_unlocked(&buf
, &size
);
1538 fputs("DeviceAllow=\n", f
);
1539 LIST_FOREACH(device_allow
, a
, c
->device_allow
)
1540 fprintf(f
, "DeviceAllow=%s %s%s%s\n", a
->path
, a
->r
? "r" : "", a
->w
? "w" : "", a
->m
? "m" : "");
1542 r
= fflush_and_check(f
);
1545 unit_write_setting(u
, flags
, name
, buf
);
1550 } else if (streq(name
, "IPAccounting")) {
1553 r
= sd_bus_message_read(message
, "b", &b
);
1557 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1558 c
->ip_accounting
= b
;
1560 unit_invalidate_cgroup_bpf(u
);
1561 unit_write_settingf(u
, flags
, name
, "IPAccounting=%s", yes_no(b
));
1566 } else if (STR_IN_SET(name
, "IPAddressAllow", "IPAddressDeny")) {
1567 IPAddressAccessItem
**list
;
1570 list
= streq(name
, "IPAddressAllow") ? &c
->ip_address_allow
: &c
->ip_address_deny
;
1572 r
= sd_bus_message_enter_container(message
, 'a', "(iayu)");
1582 r
= sd_bus_message_enter_container(message
, 'r', "iayu");
1588 r
= sd_bus_message_read(message
, "i", &family
);
1592 if (!IN_SET(family
, AF_INET
, AF_INET6
))
1593 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "%s= expects IPv4 or IPv6 addresses only.", name
);
1595 r
= sd_bus_message_read_array(message
, 'y', &ap
, &an
);
1599 if (an
!= FAMILY_ADDRESS_SIZE(family
))
1600 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "IP address has wrong size for family (%s, expected %zu, got %zu)",
1601 af_to_name(family
), FAMILY_ADDRESS_SIZE(family
), an
);
1603 r
= sd_bus_message_read(message
, "u", &prefixlen
);
1607 if (prefixlen
> FAMILY_ADDRESS_SIZE(family
)*8)
1608 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
));
1610 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1611 IPAddressAccessItem
*item
;
1613 item
= new0(IPAddressAccessItem
, 1);
1617 item
->family
= family
;
1618 item
->prefixlen
= prefixlen
;
1619 memcpy(&item
->address
, ap
, an
);
1621 LIST_PREPEND(items
, *list
, item
);
1624 r
= sd_bus_message_exit_container(message
);
1631 r
= sd_bus_message_exit_container(message
);
1635 *list
= ip_address_access_reduce(*list
);
1637 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1638 _cleanup_free_
char *buf
= NULL
;
1639 _cleanup_fclose_
FILE *f
= NULL
;
1640 IPAddressAccessItem
*item
;
1644 *list
= ip_address_access_free_all(*list
);
1646 unit_invalidate_cgroup_bpf(u
);
1647 f
= open_memstream_unlocked(&buf
, &size
);
1654 LIST_FOREACH(items
, item
, *list
) {
1655 char buffer
[CONST_MAX(INET_ADDRSTRLEN
, INET6_ADDRSTRLEN
)];
1658 if (!inet_ntop(item
->family
, &item
->address
, buffer
, sizeof(buffer
)))
1659 return errno_or_else(EINVAL
);
1661 fprintf(f
, "%s=%s/%u\n", name
, buffer
, item
->prefixlen
);
1664 r
= fflush_and_check(f
);
1668 unit_write_setting(u
, flags
, name
, buf
);
1674 if (STR_IN_SET(name
, "ManagedOOMSwap", "ManagedOOMMemoryPressure")) {
1675 ManagedOOMMode
*cgroup_mode
= streq(name
, "ManagedOOMSwap") ? &c
->moom_swap
: &c
->moom_mem_pressure
;
1679 if (!UNIT_VTABLE(u
)->can_set_managed_oom
)
1680 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Cannot set %s for this unit type", name
);
1682 r
= sd_bus_message_read(message
, "s", &mode
);
1686 m
= managed_oom_mode_from_string(mode
);
1690 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1692 unit_write_settingf(u
, flags
, name
, "%s=%s", name
, mode
);
1695 (void) manager_varlink_send_managed_oom_update(u
);
1699 if (streq(name
, "ManagedOOMMemoryPressureLimitPermyriad")) {
1702 if (!UNIT_VTABLE(u
)->can_set_managed_oom
)
1703 return sd_bus_error_setf(error
, SD_BUS_ERROR_INVALID_ARGS
, "Cannot set %s for this unit type", name
);
1705 r
= sd_bus_message_read(message
, "u", &v
);
1712 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
1713 c
->moom_mem_pressure_limit_permyriad
= v
;
1714 unit_write_settingf(u
, flags
, name
, "ManagedOOMMemoryPressureLimit=%" PRIu32
".%02" PRIu32
"%%", v
/ 100, v
% 100);
1717 if (c
->moom_mem_pressure
== MANAGED_OOM_KILL
)
1718 (void) manager_varlink_send_managed_oom_update(u
);
1723 if (streq(name
, "DisableControllers") || (u
->transient
&& u
->load_state
== UNIT_STUB
))
1724 return bus_cgroup_set_transient_property(u
, c
, name
, message
, flags
, error
);