]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/core/dbus-mount.c
core: general cgroup rework
[thirdparty/systemd.git] / src / core / dbus-mount.c
CommitLineData
d6c9574f 1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4139c1b2
LP
2
3/***
4 This file is part of systemd.
5
6 Copyright 2010 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
5430f7f2
LP
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
4139c1b2
LP
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5430f7f2 16 Lesser General Public License for more details.
4139c1b2 17
5430f7f2 18 You should have received a copy of the GNU Lesser General Public License
4139c1b2
LP
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
4e85aff4
LP
22#include <errno.h>
23
4139c1b2 24#include "dbus-unit.h"
4139c1b2 25#include "dbus-execute.h"
4ad49000
LP
26#include "dbus-kill.h"
27#include "dbus-cgroup.h"
bfebab7f 28#include "dbus-common.h"
cad45ba1 29#include "selinux-access.h"
4ad49000 30#include "dbus-mount.h"
4139c1b2 31
4288f619
LP
32#define BUS_MOUNT_INTERFACE \
33 " <interface name=\"org.freedesktop.systemd1.Mount\">\n" \
34 " <property name=\"Where\" type=\"s\" access=\"read\"/>\n" \
35 " <property name=\"What\" type=\"s\" access=\"read\"/>\n" \
36 " <property name=\"Options\" type=\"s\" access=\"read\"/>\n" \
37 " <property name=\"Type\" type=\"s\" access=\"read\"/>\n" \
38 " <property name=\"TimeoutUSec\" type=\"t\" access=\"read\"/>\n" \
fe68089d
LP
39 BUS_EXEC_COMMAND_INTERFACE("ExecMount") \
40 BUS_EXEC_COMMAND_INTERFACE("ExecUnmount") \
41 BUS_EXEC_COMMAND_INTERFACE("ExecRemount") \
4288f619 42 BUS_EXEC_CONTEXT_INTERFACE \
4819ff03 43 BUS_KILL_CONTEXT_INTERFACE \
4288f619 44 " <property name=\"ControlPID\" type=\"u\" access=\"read\"/>\n" \
5bd07073 45 " <property name=\"DirectoryMode\" type=\"u\" access=\"read\"/>\n" \
9d2f5178 46 " <property name=\"Result\" type=\"s\" access=\"read\"/>\n" \
4288f619
LP
47 " </interface>\n"
48
49#define INTROSPECTION \
50 DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
51 "<node>\n" \
52 BUS_UNIT_INTERFACE \
53 BUS_MOUNT_INTERFACE \
54 BUS_PROPERTIES_INTERFACE \
c4e2ceae 55 BUS_PEER_INTERFACE \
4288f619
LP
56 BUS_INTROSPECTABLE_INTERFACE \
57 "</node>\n"
58
05feefe0
LP
59#define INTERFACES_LIST \
60 BUS_UNIT_INTERFACES_LIST \
61 "org.freedesktop.systemd1.Mount\0"
62
9a60da28 63const char bus_mount_interface[] _introspect_("Mount") = BUS_MOUNT_INTERFACE;
4139c1b2 64
c4e2ceae
LP
65const char bus_mount_invalidating_properties[] =
66 "What\0"
67 "Options\0"
68 "Type\0"
69 "ExecMount\0"
70 "ExecUnmount\0"
71 "ExecRemount\0"
9d2f5178
LP
72 "ControlPID\0"
73 "Result\0";
c4e2ceae 74
bfebab7f 75static int bus_mount_append_what(DBusMessageIter *i, const char *property, void *data) {
4e85aff4
LP
76 Mount *m = data;
77 const char *d;
78
4e85aff4
LP
79 assert(i);
80 assert(property);
81 assert(m);
82
83 if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.what)
84 d = m->parameters_proc_self_mountinfo.what;
85 else if (m->from_fragment && m->parameters_fragment.what)
86 d = m->parameters_fragment.what;
4e85aff4
LP
87 else
88 d = "";
89
90 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
91 return -ENOMEM;
92
93 return 0;
94}
95
bfebab7f 96static int bus_mount_append_options(DBusMessageIter *i, const char *property, void *data) {
4e85aff4
LP
97 Mount *m = data;
98 const char *d;
99
4e85aff4
LP
100 assert(i);
101 assert(property);
102 assert(m);
103
104 if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.options)
105 d = m->parameters_proc_self_mountinfo.options;
106 else if (m->from_fragment && m->parameters_fragment.options)
107 d = m->parameters_fragment.options;
4e85aff4
LP
108 else
109 d = "";
110
111 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
112 return -ENOMEM;
113
114 return 0;
115}
116
bfebab7f 117static int bus_mount_append_type(DBusMessageIter *i, const char *property, void *data) {
4e85aff4
LP
118 Mount *m = data;
119 const char *d;
120
4e85aff4
LP
121 assert(i);
122 assert(property);
123 assert(m);
124
125 if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.fstype)
126 d = m->parameters_proc_self_mountinfo.fstype;
127 else if (m->from_fragment && m->parameters_fragment.fstype)
128 d = m->parameters_fragment.fstype;
4e85aff4
LP
129 else
130 d = "";
131
132 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
133 return -ENOMEM;
134
135 return 0;
136}
137
9d2f5178
LP
138static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_mount_append_mount_result, mount_result, MountResult);
139
d200735e
MS
140static const BusProperty bus_mount_properties[] = {
141 { "Where", bus_property_append_string, "s", offsetof(Mount, where), true },
142 { "What", bus_mount_append_what, "s", 0 },
143 { "Options", bus_mount_append_options, "s", 0 },
144 { "Type", bus_mount_append_type, "s", 0 },
145 { "TimeoutUSec", bus_property_append_usec, "t", offsetof(Mount, timeout_usec) },
146 BUS_EXEC_COMMAND_PROPERTY("ExecMount", offsetof(Mount, exec_command[MOUNT_EXEC_MOUNT]), false),
147 BUS_EXEC_COMMAND_PROPERTY("ExecUnmount", offsetof(Mount, exec_command[MOUNT_EXEC_UNMOUNT]), false),
148 BUS_EXEC_COMMAND_PROPERTY("ExecRemount", offsetof(Mount, exec_command[MOUNT_EXEC_REMOUNT]), false),
149 { "ControlPID", bus_property_append_pid, "u", offsetof(Mount, control_pid) },
150 { "DirectoryMode", bus_property_append_mode, "u", offsetof(Mount, directory_mode) },
9d2f5178 151 { "Result", bus_mount_append_mount_result, "s", offsetof(Mount, result) },
d200735e
MS
152 { NULL, }
153};
154
5e8d1c9a 155DBusHandlerResult bus_mount_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
ac155bb8 156 Mount *m = MOUNT(u);
d200735e
MS
157
158 const BusBoundProperties bps[] = {
4ad49000
LP
159 { "org.freedesktop.systemd1.Unit", bus_unit_properties, u },
160 { "org.freedesktop.systemd1.Mount", bus_mount_properties, m },
161 { "org.freedesktop.systemd1.Mount", bus_exec_context_properties, &m->exec_context },
162 { "org.freedesktop.systemd1.Mount", bus_kill_context_properties, &m->kill_context },
163 { "org.freedesktop.systemd1.Mount", bus_cgroup_context_properties, &m->cgroup_context },
d200735e 164 { NULL, }
4139c1b2
LP
165 };
166
cad45ba1
LP
167 SELINUX_UNIT_ACCESS_CHECK(u, c, message, "status");
168
d200735e 169 return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, bps );
4139c1b2 170}