]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/dbus-swap.c
Merge pull request #2589 from keszybz/resolve-tool-2
[thirdparty/systemd.git] / src / core / dbus-swap.c
1 /***
2 This file is part of systemd.
3
4 Copyright 2010 Lennart Poettering
5 Copyright 2010 Maarten Lankhorst
6
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19 ***/
20
21 #include "bus-util.h"
22 #include "dbus-cgroup.h"
23 #include "dbus-execute.h"
24 #include "dbus-swap.h"
25 #include "string-util.h"
26 #include "swap.h"
27 #include "unit.h"
28
29 static int property_get_priority(
30 sd_bus *bus,
31 const char *path,
32 const char *interface,
33 const char *property,
34 sd_bus_message *reply,
35 void *userdata,
36 sd_bus_error *error) {
37
38 Swap *s = SWAP(userdata);
39 int p;
40
41 assert(bus);
42 assert(reply);
43 assert(s);
44
45 if (s->from_proc_swaps)
46 p = s->parameters_proc_swaps.priority;
47 else if (s->from_fragment)
48 p = s->parameters_fragment.priority;
49 else
50 p = -1;
51
52 return sd_bus_message_append(reply, "i", p);
53 }
54
55 static int property_get_options(
56 sd_bus *bus,
57 const char *path,
58 const char *interface,
59 const char *property,
60 sd_bus_message *reply,
61 void *userdata,
62 sd_bus_error *error) {
63
64 Swap *s = SWAP(userdata);
65 const char *options = NULL;
66
67 assert(bus);
68 assert(reply);
69 assert(s);
70
71 if (s->from_fragment)
72 options = s->parameters_fragment.options;
73
74 return sd_bus_message_append(reply, "s", options);
75 }
76
77 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, swap_result, SwapResult);
78
79 const sd_bus_vtable bus_swap_vtable[] = {
80 SD_BUS_VTABLE_START(0),
81 SD_BUS_PROPERTY("What", "s", NULL, offsetof(Swap, what), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
82 SD_BUS_PROPERTY("Priority", "i", property_get_priority, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
83 SD_BUS_PROPERTY("Options", "s", property_get_options, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
84 SD_BUS_PROPERTY("TimeoutUSec", "t", bus_property_get_usec, offsetof(Swap, timeout_usec), SD_BUS_VTABLE_PROPERTY_CONST),
85 SD_BUS_PROPERTY("ControlPID", "u", bus_property_get_pid, offsetof(Swap, control_pid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
86 SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Swap, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
87 BUS_EXEC_COMMAND_VTABLE("ExecActivate", offsetof(Swap, exec_command[SWAP_EXEC_ACTIVATE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
88 BUS_EXEC_COMMAND_VTABLE("ExecDeactivate", offsetof(Swap, exec_command[SWAP_EXEC_DEACTIVATE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
89 SD_BUS_VTABLE_END
90 };
91
92 int bus_swap_set_property(
93 Unit *u,
94 const char *name,
95 sd_bus_message *message,
96 UnitSetPropertiesMode mode,
97 sd_bus_error *error) {
98
99 Swap *s = SWAP(u);
100
101 assert(s);
102 assert(name);
103 assert(message);
104
105 return bus_cgroup_set_property(u, &s->cgroup_context, name, message, mode, error);
106 }
107
108 int bus_swap_commit_properties(Unit *u) {
109 assert(u);
110
111 unit_update_cgroup_members_masks(u);
112 unit_realize_cgroup(u);
113
114 return 0;
115 }