1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /***
3 Copyright © 2010 Maarten Lankhorst
4 ***/
5
6 #include "bus-get-properties.h"
7 #include "dbus-cgroup.h"
8 #include "dbus-execute.h"
9 #include "dbus-swap.h"
10 #include "string-util.h"
11 #include "swap.h"
12 #include "unit.h"
13
swap_get_priority(Swap * s)14 static int swap_get_priority(Swap *s) {
15 assert(s);
16
17 if (s->from_proc_swaps && s->parameters_proc_swaps.priority_set)
18 return s->parameters_proc_swaps.priority;
19
20 if (s->from_fragment && s->parameters_fragment.priority_set)
21 return s->parameters_fragment.priority;
22
23 return -1;
24 }
25
swap_get_options(Swap * s)26 static const char *swap_get_options(Swap *s) {
27 assert(s);
28
29 if (s->from_fragment)
30 return s->parameters_fragment.options;
31
32 return NULL;
33 }
34
35 static BUS_DEFINE_PROPERTY_GET(property_get_priority, "i", Swap, swap_get_priority);
36 static BUS_DEFINE_PROPERTY_GET(property_get_options, "s", Swap, swap_get_options);
37 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, swap_result, SwapResult);
38
39 const sd_bus_vtable bus_swap_vtable[] = {
40 SD_BUS_VTABLE_START(0),
41 SD_BUS_PROPERTY("What", "s", NULL, offsetof(Swap, what), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
42 SD_BUS_PROPERTY("Priority", "i", property_get_priority, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
43 SD_BUS_PROPERTY("Options", "s", property_get_options, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
44 SD_BUS_PROPERTY("TimeoutUSec", "t", bus_property_get_usec, offsetof(Swap, timeout_usec), SD_BUS_VTABLE_PROPERTY_CONST),
45 SD_BUS_PROPERTY("ControlPID", "u", bus_property_get_pid, offsetof(Swap, control_pid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
46 SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Swap, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
47 SD_BUS_PROPERTY("UID", "u", bus_property_get_uid, offsetof(Unit, ref_uid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
48 SD_BUS_PROPERTY("GID", "u", bus_property_get_gid, offsetof(Unit, ref_gid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
49 BUS_EXEC_COMMAND_VTABLE("ExecActivate", offsetof(Swap, exec_command[SWAP_EXEC_ACTIVATE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
50 BUS_EXEC_COMMAND_VTABLE("ExecDeactivate", offsetof(Swap, exec_command[SWAP_EXEC_DEACTIVATE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
51 SD_BUS_VTABLE_END
52 };
53
bus_swap_set_property(Unit * u,const char * name,sd_bus_message * message,UnitWriteFlags flags,sd_bus_error * error)54 int bus_swap_set_property(
55 Unit *u,
56 const char *name,
57 sd_bus_message *message,
58 UnitWriteFlags flags,
59 sd_bus_error *error) {
60
61 Swap *s = SWAP(u);
62
63 assert(s);
64 assert(name);
65 assert(message);
66
67 return bus_cgroup_set_property(u, &s->cgroup_context, name, message, flags, error);
68 }
69
bus_swap_commit_properties(Unit * u)70 int bus_swap_commit_properties(Unit *u) {
71 assert(u);
72
73 unit_realize_cgroup(u);
74
75 return 0;
76 }
77