| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "bus-get-properties.h" |
| 4 |
#include "dbus-cgroup.h" |
| 5 |
#include "dbus-slice.h" |
| 6 |
#include "dbus-util.h" |
| 7 |
#include "slice.h" |
| 8 |
#include "string-util.h" |
| 9 |
#include "unit.h" |
| 10 |
|
| 11 |
static int property_get_currently_active( |
| 12 |
sd_bus *bus, |
| 13 |
const char *path, |
| 14 |
const char *interface, |
| 15 |
const char *property, |
| 16 |
sd_bus_message *reply, |
| 17 |
void *userdata, |
| 18 |
sd_bus_error *reterr_error) { |
| 19 |
|
| 20 |
Slice *s = ASSERT_PTR(userdata); |
| 21 |
|
| 22 |
assert(bus); |
| 23 |
assert(reply); |
| 24 |
|
| 25 |
return sd_bus_message_append( |
| 26 |
reply, |
| 27 |
"u", |
| 28 |
(uint32_t) slice_get_currently_active(s, /* ignore= */ NULL, /* with_pending= */ false)); |
| 29 |
} |
| 30 |
|
| 31 |
const sd_bus_vtable bus_slice_vtable[] = { |
| 32 |
SD_BUS_VTABLE_START(0), |
| 33 |
/* The following are currently constant, but we should change that eventually (i.e. open them up via |
| 34 |
* systemctl set-property), hence they aren't marked as constant */ |
| 35 |
SD_BUS_PROPERTY("ConcurrencyHardMax", "u", bus_property_get_unsigned, offsetof(Slice, concurrency_hard_max), 0), |
| 36 |
SD_BUS_PROPERTY("ConcurrencySoftMax", "u", bus_property_get_unsigned, offsetof(Slice, concurrency_soft_max), 0), |
| 37 |
SD_BUS_PROPERTY("NCurrentlyActive", "u", property_get_currently_active, 0, 0), |
| 38 |
SD_BUS_VTABLE_END |
| 39 |
}; |
| 40 |
|
| 41 |
static int bus_slice_set_transient_property( |
| 42 |
Slice *s, |
| 43 |
const char *name, |
| 44 |
sd_bus_message *message, |
| 45 |
UnitWriteFlags flags, |
| 46 |
sd_bus_error *reterr_error) { |
| 47 |
|
| 48 |
Unit *u = UNIT(s); |
| 49 |
|
| 50 |
assert(s); |
| 51 |
assert(name); |
| 52 |
assert(message); |
| 53 |
|
| 54 |
flags |= UNIT_PRIVATE; |
| 55 |
|
| 56 |
if (streq(name, "ConcurrencyHardMax")) |
| 57 |
return bus_set_transient_unsigned(u, name, &s->concurrency_hard_max, message, flags, reterr_error); |
| 58 |
|
| 59 |
if (streq(name, "ConcurrencySoftMax")) |
| 60 |
return bus_set_transient_unsigned(u, name, &s->concurrency_soft_max, message, flags, reterr_error); |
| 61 |
|
| 62 |
return 0; |
| 63 |
} |
| 64 |
|
| 65 |
int bus_slice_set_property( |
| 66 |
Unit *u, |
| 67 |
const char *name, |
| 68 |
sd_bus_message *message, |
| 69 |
UnitWriteFlags flags, |
| 70 |
sd_bus_error *reterr_error) { |
| 71 |
|
| 72 |
Slice *s = SLICE(u); |
| 73 |
int r; |
| 74 |
|
| 75 |
assert(name); |
| 76 |
assert(u); |
| 77 |
|
| 78 |
r = bus_cgroup_set_property(u, &s->cgroup_context, name, message, flags, reterr_error); |
| 79 |
if (r != 0) |
| 80 |
return r; |
| 81 |
|
| 82 |
if (u->transient && u->load_state == UNIT_STUB) { |
| 83 |
/* This is a transient unit, let's allow a little more */ |
| 84 |
|
| 85 |
r = bus_slice_set_transient_property(s, name, message, flags, reterr_error); |
| 86 |
if (r != 0) |
| 87 |
return r; |
| 88 |
} |
| 89 |
|
| 90 |
return 0; |
| 91 |
} |
| 92 |
|
| 93 |
int bus_slice_commit_properties(Unit *u) { |
| 94 |
assert(u); |
| 95 |
|
| 96 |
(void) unit_realize_cgroup(u); |
| 97 |
|
| 98 |
return 0; |
| 99 |
} |