]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/core/dbus-swap.c
core: s/reexection/reexecution/ typo fix
[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
718db961
LP
23#include "unit.h"
24#include "swap.h"
15412f29 25#include "dbus-execute.h"
4ad49000 26#include "dbus-cgroup.h"
4ad49000 27#include "dbus-swap.h"
718db961
LP
28#include "bus-util.h"
29
30static int property_get_priority(
31 sd_bus *bus,
32 const char *path,
33 const char *interface,
34 const char *property,
35 sd_bus_message *reply,
ebcf1f97
LP
36 void *userdata,
37 sd_bus_error *error) {
718db961
LP
38
39 Swap *s = SWAP(userdata);
40 int p;
41
42 assert(bus);
43 assert(reply);
4e85aff4
LP
44 assert(s);
45
46 if (s->from_proc_swaps)
718db961 47 p = s->parameters_proc_swaps.priority;
4e85aff4 48 else if (s->from_fragment)
718db961 49 p = s->parameters_fragment.priority;
4e85aff4 50 else
718db961 51 p = -1;
4e85aff4 52
718db961 53 return sd_bus_message_append(reply, "i", p);
4e85aff4
LP
54}
55
47cb901e 56static int property_get_options(
4afbccde
ZJS
57 sd_bus *bus,
58 const char *path,
59 const char *interface,
60 const char *property,
61 sd_bus_message *reply,
62 void *userdata,
63 sd_bus_error *error) {
64
65 Swap *s = SWAP(userdata);
47cb901e 66 const char *options = NULL;
4afbccde
ZJS
67
68 assert(bus);
69 assert(reply);
70 assert(s);
71
72 if (s->from_fragment)
47cb901e
LP
73 options = s->parameters_fragment.options;
74
75 return sd_bus_message_append(reply, "s", options);
4afbccde
ZJS
76}
77
718db961
LP
78static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, swap_result, SwapResult);
79
80const sd_bus_vtable bus_swap_vtable[] = {
81 SD_BUS_VTABLE_START(0),
82 SD_BUS_PROPERTY("What", "s", NULL, offsetof(Swap, what), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
83 SD_BUS_PROPERTY("Priority", "i", property_get_priority, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
47cb901e 84 SD_BUS_PROPERTY("Options", "s", property_get_options, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
556089dc 85 SD_BUS_PROPERTY("TimeoutUSec", "t", bus_property_get_usec, offsetof(Swap, timeout_usec), SD_BUS_VTABLE_PROPERTY_CONST),
718db961
LP
86 SD_BUS_PROPERTY("ControlPID", "u", bus_property_get_pid, offsetof(Swap, control_pid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
87 SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Swap, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
556089dc
LP
88 BUS_EXEC_COMMAND_VTABLE("ExecActivate", offsetof(Swap, exec_command[SWAP_EXEC_ACTIVATE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
89 BUS_EXEC_COMMAND_VTABLE("ExecDeactivate", offsetof(Swap, exec_command[SWAP_EXEC_DEACTIVATE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
718db961 90 SD_BUS_VTABLE_END
d200735e
MS
91};
92
74c964d3
LP
93int bus_swap_set_property(
94 Unit *u,
95 const char *name,
718db961 96 sd_bus_message *message,
74c964d3 97 UnitSetPropertiesMode mode,
718db961 98 sd_bus_error *error) {
74c964d3
LP
99
100 Swap *s = SWAP(u);
74c964d3 101
718db961 102 assert(s);
74c964d3 103 assert(name);
718db961 104 assert(message);
74c964d3 105
718db961 106 return bus_cgroup_set_property(u, &s->cgroup_context, name, message, mode, error);
74c964d3
LP
107}
108
109int bus_swap_commit_properties(Unit *u) {
110 assert(u);
111
bc432dc7 112 unit_update_cgroup_members_masks(u);
74c964d3 113 unit_realize_cgroup(u);
bc432dc7 114
74c964d3
LP
115 return 0;
116}