2 This file is part of systemd.
4 Copyright 2010 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 #include "dbus-cgroup.h"
22 #include "dbus-execute.h"
23 #include "dbus-kill.h"
24 #include "dbus-mount.h"
26 #include "string-util.h"
29 static int property_get_what(
32 const char *interface
,
34 sd_bus_message
*reply
,
36 sd_bus_error
*error
) {
45 if (m
->from_proc_self_mountinfo
&& m
->parameters_proc_self_mountinfo
.what
)
46 d
= m
->parameters_proc_self_mountinfo
.what
;
47 else if (m
->from_fragment
&& m
->parameters_fragment
.what
)
48 d
= m
->parameters_fragment
.what
;
52 return sd_bus_message_append(reply
, "s", d
);
55 static int property_get_options(
58 const char *interface
,
60 sd_bus_message
*reply
,
62 sd_bus_error
*error
) {
71 if (m
->from_proc_self_mountinfo
&& m
->parameters_proc_self_mountinfo
.options
)
72 d
= m
->parameters_proc_self_mountinfo
.options
;
73 else if (m
->from_fragment
&& m
->parameters_fragment
.options
)
74 d
= m
->parameters_fragment
.options
;
78 return sd_bus_message_append(reply
, "s", d
);
81 static int property_get_type(
84 const char *interface
,
86 sd_bus_message
*reply
,
88 sd_bus_error
*error
) {
90 const char *fstype
= NULL
;
97 if (m
->from_proc_self_mountinfo
&& m
->parameters_proc_self_mountinfo
.fstype
)
98 fstype
= m
->parameters_proc_self_mountinfo
.fstype
;
99 else if (m
->from_fragment
&& m
->parameters_fragment
.fstype
)
100 fstype
= m
->parameters_fragment
.fstype
;
102 return sd_bus_message_append(reply
, "s", fstype
);
105 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result
, mount_result
, MountResult
);
107 const sd_bus_vtable bus_mount_vtable
[] = {
108 SD_BUS_VTABLE_START(0),
109 SD_BUS_PROPERTY("Where", "s", NULL
, offsetof(Mount
, where
), SD_BUS_VTABLE_PROPERTY_CONST
),
110 SD_BUS_PROPERTY("What", "s", property_get_what
, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
111 SD_BUS_PROPERTY("Options","s", property_get_options
, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
112 SD_BUS_PROPERTY("Type", "s", property_get_type
, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
113 SD_BUS_PROPERTY("TimeoutUSec", "t", bus_property_get_usec
, offsetof(Mount
, timeout_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
114 SD_BUS_PROPERTY("ControlPID", "u", bus_property_get_pid
, offsetof(Mount
, control_pid
), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
115 SD_BUS_PROPERTY("DirectoryMode", "u", bus_property_get_mode
, offsetof(Mount
, directory_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
116 SD_BUS_PROPERTY("SloppyOptions", "b", bus_property_get_bool
, offsetof(Mount
, sloppy_options
), SD_BUS_VTABLE_PROPERTY_CONST
),
117 SD_BUS_PROPERTY("LazyUnmount", "b", bus_property_get_bool
, offsetof(Mount
, lazy_unmount
), SD_BUS_VTABLE_PROPERTY_CONST
),
118 SD_BUS_PROPERTY("ForceUnmount", "b", bus_property_get_bool
, offsetof(Mount
, force_unmount
), SD_BUS_VTABLE_PROPERTY_CONST
),
119 SD_BUS_PROPERTY("Result", "s", property_get_result
, offsetof(Mount
, result
), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
120 SD_BUS_PROPERTY("UID", "u", NULL
, offsetof(Unit
, ref_uid
), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
121 SD_BUS_PROPERTY("GID", "u", NULL
, offsetof(Unit
, ref_gid
), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
122 BUS_EXEC_COMMAND_VTABLE("ExecMount", offsetof(Mount
, exec_command
[MOUNT_EXEC_MOUNT
]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION
),
123 BUS_EXEC_COMMAND_VTABLE("ExecUnmount", offsetof(Mount
, exec_command
[MOUNT_EXEC_UNMOUNT
]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION
),
124 BUS_EXEC_COMMAND_VTABLE("ExecRemount", offsetof(Mount
, exec_command
[MOUNT_EXEC_REMOUNT
]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION
),
128 static int bus_mount_set_transient_property(
131 sd_bus_message
*message
,
132 UnitSetPropertiesMode mode
,
133 sd_bus_error
*error
) {
135 const char *new_property
;
144 if (streq(name
, "What"))
145 property
= &m
->parameters_fragment
.what
;
146 else if (streq(name
, "Options"))
147 property
= &m
->parameters_fragment
.options
;
148 else if (streq(name
, "Type"))
149 property
= &m
->parameters_fragment
.fstype
;
153 r
= sd_bus_message_read(message
, "s", &new_property
);
157 if (mode
!= UNIT_CHECK
) {
158 p
= strdup(new_property
);
162 unit_write_drop_in_format(UNIT(m
), mode
, name
, "[Mount]\n%s=%s\n",
172 int bus_mount_set_property(
175 sd_bus_message
*message
,
176 UnitSetPropertiesMode mode
,
177 sd_bus_error
*error
) {
186 r
= bus_cgroup_set_property(u
, &m
->cgroup_context
, name
, message
, mode
, error
);
190 if (u
->transient
&& u
->load_state
== UNIT_STUB
) {
191 /* This is a transient unit, let's load a little more */
193 r
= bus_mount_set_transient_property(m
, name
, message
, mode
, error
);
197 r
= bus_exec_context_set_transient_property(u
, &m
->exec_context
, name
, message
, mode
, error
);
201 r
= bus_kill_context_set_transient_property(u
, &m
->kill_context
, name
, message
, mode
, error
);
209 int bus_mount_commit_properties(Unit
*u
) {
212 unit_update_cgroup_members_masks(u
);
213 unit_realize_cgroup(u
);