chiark / gitweb /
core: refuse doing %h, %s, %U specifier resolving in PID 1
[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 BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, swap_result, SwapResult);
59
60 const sd_bus_vtable bus_swap_vtable[] = {
61         SD_BUS_VTABLE_START(0),
62         SD_BUS_PROPERTY("What", "s", NULL, offsetof(Swap, what), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
63         SD_BUS_PROPERTY("Priority", "i", property_get_priority, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
64         SD_BUS_PROPERTY("TimeoutUSec", "t", bus_property_get_usec, offsetof(Swap, timeout_usec), 0),
65         SD_BUS_PROPERTY("ControlPID", "u", bus_property_get_pid, offsetof(Swap, control_pid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
66         SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Swap, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
67         BUS_EXEC_COMMAND_VTABLE("ExecActivate", offsetof(Swap, exec_command[SWAP_EXEC_ACTIVATE]), 0),
68         BUS_EXEC_COMMAND_VTABLE("ExecDeactivate", offsetof(Swap, exec_command[SWAP_EXEC_DEACTIVATE]), 0),
69         SD_BUS_VTABLE_END
70 };
71
72 const char* const bus_swap_changing_properties[] = {
73         "What",
74         "Priority",
75         "ControlPID",
76         "Result",
77         NULL
78 };
79
80 int bus_swap_set_property(
81                 Unit *u,
82                 const char *name,
83                 sd_bus_message *message,
84                 UnitSetPropertiesMode mode,
85                 sd_bus_error *error) {
86
87         Swap *s = SWAP(u);
88
89         assert(s);
90         assert(name);
91         assert(message);
92
93         return bus_cgroup_set_property(u, &s->cgroup_context, name, message, mode, error);
94 }
95
96 int bus_swap_commit_properties(Unit *u) {
97         assert(u);
98
99         unit_realize_cgroup(u);
100         return 0;
101 }