]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
07b0b134 ML |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2010 Lennart Poettering | |
6 | Copyright 2010 Maarten Lankhorst | |
07b0b134 ML |
7 | ***/ |
8 | ||
07630cea | 9 | #include "bus-util.h" |
4ad49000 | 10 | #include "dbus-cgroup.h" |
07630cea | 11 | #include "dbus-execute.h" |
cf0fbc49 | 12 | #include "dbus-swap.h" |
07630cea LP |
13 | #include "string-util.h" |
14 | #include "swap.h" | |
15 | #include "unit.h" | |
718db961 LP |
16 | |
17 | static int property_get_priority( | |
18 | sd_bus *bus, | |
19 | const char *path, | |
20 | const char *interface, | |
21 | const char *property, | |
22 | sd_bus_message *reply, | |
ebcf1f97 LP |
23 | void *userdata, |
24 | sd_bus_error *error) { | |
718db961 LP |
25 | |
26 | Swap *s = SWAP(userdata); | |
27 | int p; | |
28 | ||
29 | assert(bus); | |
30 | assert(reply); | |
4e85aff4 LP |
31 | assert(s); |
32 | ||
33 | if (s->from_proc_swaps) | |
718db961 | 34 | p = s->parameters_proc_swaps.priority; |
4e85aff4 | 35 | else if (s->from_fragment) |
718db961 | 36 | p = s->parameters_fragment.priority; |
4e85aff4 | 37 | else |
718db961 | 38 | p = -1; |
4e85aff4 | 39 | |
718db961 | 40 | return sd_bus_message_append(reply, "i", p); |
4e85aff4 LP |
41 | } |
42 | ||
47cb901e | 43 | static int property_get_options( |
4afbccde ZJS |
44 | sd_bus *bus, |
45 | const char *path, | |
46 | const char *interface, | |
47 | const char *property, | |
48 | sd_bus_message *reply, | |
49 | void *userdata, | |
50 | sd_bus_error *error) { | |
51 | ||
52 | Swap *s = SWAP(userdata); | |
47cb901e | 53 | const char *options = NULL; |
4afbccde ZJS |
54 | |
55 | assert(bus); | |
56 | assert(reply); | |
57 | assert(s); | |
58 | ||
59 | if (s->from_fragment) | |
47cb901e LP |
60 | options = s->parameters_fragment.options; |
61 | ||
62 | return sd_bus_message_append(reply, "s", options); | |
4afbccde ZJS |
63 | } |
64 | ||
718db961 LP |
65 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, swap_result, SwapResult); |
66 | ||
67 | const sd_bus_vtable bus_swap_vtable[] = { | |
68 | SD_BUS_VTABLE_START(0), | |
69 | SD_BUS_PROPERTY("What", "s", NULL, offsetof(Swap, what), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), | |
70 | SD_BUS_PROPERTY("Priority", "i", property_get_priority, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), | |
47cb901e | 71 | SD_BUS_PROPERTY("Options", "s", property_get_options, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
556089dc | 72 | SD_BUS_PROPERTY("TimeoutUSec", "t", bus_property_get_usec, offsetof(Swap, timeout_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
718db961 LP |
73 | SD_BUS_PROPERTY("ControlPID", "u", bus_property_get_pid, offsetof(Swap, control_pid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
74 | SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Swap, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), | |
00d9ef85 LP |
75 | SD_BUS_PROPERTY("UID", "u", NULL, offsetof(Unit, ref_uid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
76 | SD_BUS_PROPERTY("GID", "u", NULL, offsetof(Unit, ref_gid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), | |
556089dc LP |
77 | BUS_EXEC_COMMAND_VTABLE("ExecActivate", offsetof(Swap, exec_command[SWAP_EXEC_ACTIVATE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
78 | BUS_EXEC_COMMAND_VTABLE("ExecDeactivate", offsetof(Swap, exec_command[SWAP_EXEC_DEACTIVATE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), | |
718db961 | 79 | SD_BUS_VTABLE_END |
d200735e MS |
80 | }; |
81 | ||
74c964d3 LP |
82 | int bus_swap_set_property( |
83 | Unit *u, | |
84 | const char *name, | |
718db961 | 85 | sd_bus_message *message, |
2e59b241 | 86 | UnitWriteFlags flags, |
718db961 | 87 | sd_bus_error *error) { |
74c964d3 LP |
88 | |
89 | Swap *s = SWAP(u); | |
74c964d3 | 90 | |
718db961 | 91 | assert(s); |
74c964d3 | 92 | assert(name); |
718db961 | 93 | assert(message); |
74c964d3 | 94 | |
2e59b241 | 95 | return bus_cgroup_set_property(u, &s->cgroup_context, name, message, flags, error); |
74c964d3 LP |
96 | } |
97 | ||
98 | int bus_swap_commit_properties(Unit *u) { | |
99 | assert(u); | |
100 | ||
bc432dc7 | 101 | unit_update_cgroup_members_masks(u); |
74c964d3 | 102 | unit_realize_cgroup(u); |
bc432dc7 | 103 | |
74c964d3 LP |
104 | return 0; |
105 | } |