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