/src/systemd/src/core/dbus-slice.c
Line | Count | Source |
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 | 0 | sd_bus_error *error) { |
19 | |
|
20 | 0 | Slice *s = ASSERT_PTR(userdata); |
21 | |
|
22 | 0 | assert(bus); |
23 | 0 | assert(reply); |
24 | |
|
25 | 0 | return sd_bus_message_append( |
26 | 0 | reply, |
27 | 0 | "u", |
28 | 0 | (uint32_t) slice_get_currently_active(s, /* ignore= */ NULL, /* with_pending= */ false)); |
29 | 0 | } |
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 | 0 | sd_bus_error *error) { |
47 | |
|
48 | 0 | Unit *u = UNIT(s); |
49 | |
|
50 | 0 | assert(s); |
51 | 0 | assert(name); |
52 | 0 | assert(message); |
53 | |
|
54 | 0 | flags |= UNIT_PRIVATE; |
55 | |
|
56 | 0 | if (streq(name, "ConcurrencyHardMax")) |
57 | 0 | return bus_set_transient_unsigned(u, name, &s->concurrency_hard_max, message, flags, error); |
58 | | |
59 | 0 | if (streq(name, "ConcurrencySoftMax")) |
60 | 0 | return bus_set_transient_unsigned(u, name, &s->concurrency_soft_max, message, flags, error); |
61 | | |
62 | 0 | return 0; |
63 | 0 | } |
64 | | |
65 | | int bus_slice_set_property( |
66 | | Unit *u, |
67 | | const char *name, |
68 | | sd_bus_message *message, |
69 | | UnitWriteFlags flags, |
70 | 0 | sd_bus_error *error) { |
71 | |
|
72 | 0 | Slice *s = SLICE(u); |
73 | 0 | int r; |
74 | |
|
75 | 0 | assert(name); |
76 | 0 | assert(u); |
77 | |
|
78 | 0 | r = bus_cgroup_set_property(u, &s->cgroup_context, name, message, flags, error); |
79 | 0 | if (r != 0) |
80 | 0 | return r; |
81 | | |
82 | 0 | if (u->transient && u->load_state == UNIT_STUB) { |
83 | | /* This is a transient unit, let's allow a little more */ |
84 | |
|
85 | 0 | r = bus_slice_set_transient_property(s, name, message, flags, error); |
86 | 0 | if (r != 0) |
87 | 0 | return r; |
88 | 0 | } |
89 | | |
90 | 0 | return 0; |
91 | 0 | } |
92 | | |
93 | 0 | int bus_slice_commit_properties(Unit *u) { |
94 | 0 | assert(u); |
95 | |
|
96 | 0 | (void) unit_realize_cgroup(u); |
97 | |
|
98 | 0 | return 0; |
99 | 0 | } |