]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/core/dbus-swap.c
util-lib: split our string related calls from util.[ch] into its own file string...
[thirdparty/systemd.git] / src / core / dbus-swap.c
CommitLineData
d6c9574f 1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
07b0b134
ML
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
5430f7f2
LP
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
07b0b134
ML
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
5430f7f2 17 Lesser General Public License for more details.
07b0b134 18
5430f7f2 19 You should have received a copy of the GNU Lesser General Public License
07b0b134
ML
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21***/
22
07630cea 23#include "bus-util.h"
4ad49000 24#include "dbus-cgroup.h"
07630cea
LP
25#include "dbus-execute.h"
26#include "string-util.h"
27#include "swap.h"
28#include "unit.h"
4ad49000 29#include "dbus-swap.h"
718db961
LP
30
31static int property_get_priority(
32 sd_bus *bus,
33 const char *path,
34 const char *interface,
35 const char *property,
36 sd_bus_message *reply,
ebcf1f97
LP
37 void *userdata,
38 sd_bus_error *error) {
718db961
LP
39
40 Swap *s = SWAP(userdata);
41 int p;
42
43 assert(bus);
44 assert(reply);
4e85aff4
LP
45 assert(s);
46
47 if (s->from_proc_swaps)
718db961 48 p = s->parameters_proc_swaps.priority;
4e85aff4 49 else if (s->from_fragment)
718db961 50 p = s->parameters_fragment.priority;
4e85aff4 51 else
718db961 52 p = -1;
4e85aff4 53
718db961 54 return sd_bus_message_append(reply, "i", p);
4e85aff4
LP
55}
56
47cb901e 57static int property_get_options(
4afbccde
ZJS
58 sd_bus *bus,
59 const char *path,
60 const char *interface,
61 const char *property,
62 sd_bus_message *reply,
63 void *userdata,
64 sd_bus_error *error) {
65
66 Swap *s = SWAP(userdata);
47cb901e 67 const char *options = NULL;
4afbccde
ZJS
68
69 assert(bus);
70 assert(reply);
71 assert(s);
72
73 if (s->from_fragment)
47cb901e
LP
74 options = s->parameters_fragment.options;
75
76 return sd_bus_message_append(reply, "s", options);
4afbccde
ZJS
77}
78
718db961
LP
79static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, swap_result, SwapResult);
80
81const sd_bus_vtable bus_swap_vtable[] = {
82 SD_BUS_VTABLE_START(0),
83 SD_BUS_PROPERTY("What", "s", NULL, offsetof(Swap, what), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
84 SD_BUS_PROPERTY("Priority", "i", property_get_priority, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
47cb901e 85 SD_BUS_PROPERTY("Options", "s", property_get_options, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
556089dc 86 SD_BUS_PROPERTY("TimeoutUSec", "t", bus_property_get_usec, offsetof(Swap, timeout_usec), SD_BUS_VTABLE_PROPERTY_CONST),
718db961
LP
87 SD_BUS_PROPERTY("ControlPID", "u", bus_property_get_pid, offsetof(Swap, control_pid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
88 SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Swap, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
556089dc
LP
89 BUS_EXEC_COMMAND_VTABLE("ExecActivate", offsetof(Swap, exec_command[SWAP_EXEC_ACTIVATE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
90 BUS_EXEC_COMMAND_VTABLE("ExecDeactivate", offsetof(Swap, exec_command[SWAP_EXEC_DEACTIVATE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
718db961 91 SD_BUS_VTABLE_END
d200735e
MS
92};
93
74c964d3
LP
94int bus_swap_set_property(
95 Unit *u,
96 const char *name,
718db961 97 sd_bus_message *message,
74c964d3 98 UnitSetPropertiesMode mode,
718db961 99 sd_bus_error *error) {
74c964d3
LP
100
101 Swap *s = SWAP(u);
74c964d3 102
718db961 103 assert(s);
74c964d3 104 assert(name);
718db961 105 assert(message);
74c964d3 106
718db961 107 return bus_cgroup_set_property(u, &s->cgroup_context, name, message, mode, error);
74c964d3
LP
108}
109
110int bus_swap_commit_properties(Unit *u) {
111 assert(u);
112
bc432dc7 113 unit_update_cgroup_members_masks(u);
74c964d3 114 unit_realize_cgroup(u);
bc432dc7 115
74c964d3
LP
116 return 0;
117}