1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2010 Lennart Poettering
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include "dbus-cgroup.h"
23 #include "dbus-execute.h"
24 #include "dbus-kill.h"
25 #include "dbus-mount.h"
27 #include "string-util.h"
30 static int property_get_what(
33 const char *interface
,
35 sd_bus_message
*reply
,
37 sd_bus_error
*error
) {
46 if (m
->from_proc_self_mountinfo
&& m
->parameters_proc_self_mountinfo
.what
)
47 d
= m
->parameters_proc_self_mountinfo
.what
;
48 else if (m
->from_fragment
&& m
->parameters_fragment
.what
)
49 d
= m
->parameters_fragment
.what
;
51 return sd_bus_message_append(reply
, "s", d
);
54 static int property_get_options(
57 const char *interface
,
59 sd_bus_message
*reply
,
61 sd_bus_error
*error
) {
70 if (m
->from_proc_self_mountinfo
&& m
->parameters_proc_self_mountinfo
.options
)
71 d
= m
->parameters_proc_self_mountinfo
.options
;
72 else if (m
->from_fragment
&& m
->parameters_fragment
.options
)
73 d
= m
->parameters_fragment
.options
;
75 return sd_bus_message_append(reply
, "s", d
);
78 static int property_get_type(
81 const char *interface
,
83 sd_bus_message
*reply
,
85 sd_bus_error
*error
) {
87 const char *fstype
= NULL
;
94 if (m
->from_proc_self_mountinfo
&& m
->parameters_proc_self_mountinfo
.fstype
)
95 fstype
= m
->parameters_proc_self_mountinfo
.fstype
;
96 else if (m
->from_fragment
&& m
->parameters_fragment
.fstype
)
97 fstype
= m
->parameters_fragment
.fstype
;
99 return sd_bus_message_append(reply
, "s", fstype
);
102 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result
, mount_result
, MountResult
);
104 const sd_bus_vtable bus_mount_vtable
[] = {
105 SD_BUS_VTABLE_START(0),
106 SD_BUS_PROPERTY("Where", "s", NULL
, offsetof(Mount
, where
), SD_BUS_VTABLE_PROPERTY_CONST
),
107 SD_BUS_PROPERTY("What", "s", property_get_what
, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
108 SD_BUS_PROPERTY("Options","s", property_get_options
, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
109 SD_BUS_PROPERTY("Type", "s", property_get_type
, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
110 SD_BUS_PROPERTY("TimeoutUSec", "t", bus_property_get_usec
, offsetof(Mount
, timeout_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
111 SD_BUS_PROPERTY("ControlPID", "u", bus_property_get_pid
, offsetof(Mount
, control_pid
), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
112 SD_BUS_PROPERTY("DirectoryMode", "u", bus_property_get_mode
, offsetof(Mount
, directory_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
113 SD_BUS_PROPERTY("SloppyOptions", "b", bus_property_get_bool
, offsetof(Mount
, sloppy_options
), SD_BUS_VTABLE_PROPERTY_CONST
),
114 SD_BUS_PROPERTY("LazyUnmount", "b", bus_property_get_bool
, offsetof(Mount
, lazy_unmount
), SD_BUS_VTABLE_PROPERTY_CONST
),
115 SD_BUS_PROPERTY("ForceUnmount", "b", bus_property_get_bool
, offsetof(Mount
, force_unmount
), SD_BUS_VTABLE_PROPERTY_CONST
),
116 SD_BUS_PROPERTY("Result", "s", property_get_result
, offsetof(Mount
, result
), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
117 SD_BUS_PROPERTY("UID", "u", NULL
, offsetof(Unit
, ref_uid
), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
118 SD_BUS_PROPERTY("GID", "u", NULL
, offsetof(Unit
, ref_gid
), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
119 BUS_EXEC_COMMAND_VTABLE("ExecMount", offsetof(Mount
, exec_command
[MOUNT_EXEC_MOUNT
]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION
),
120 BUS_EXEC_COMMAND_VTABLE("ExecUnmount", offsetof(Mount
, exec_command
[MOUNT_EXEC_UNMOUNT
]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION
),
121 BUS_EXEC_COMMAND_VTABLE("ExecRemount", offsetof(Mount
, exec_command
[MOUNT_EXEC_REMOUNT
]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION
),
125 static int bus_mount_set_transient_property(
128 sd_bus_message
*message
,
129 UnitWriteFlags flags
,
130 sd_bus_error
*error
) {
132 const char *new_property
;
140 flags
|= UNIT_PRIVATE
;
142 if (streq(name
, "What"))
143 property
= &m
->parameters_fragment
.what
;
144 else if (streq(name
, "Options"))
145 property
= &m
->parameters_fragment
.options
;
146 else if (streq(name
, "Type"))
147 property
= &m
->parameters_fragment
.fstype
;
151 r
= sd_bus_message_read(message
, "s", &new_property
);
155 if (!UNIT_WRITE_FLAGS_NOOP(flags
)) {
157 r
= free_and_strdup(property
, new_property
);
161 unit_write_settingf(UNIT(m
), flags
|UNIT_ESCAPE_SPECIFIERS
, name
, "%s=%s", name
, new_property
);
167 int bus_mount_set_property(
170 sd_bus_message
*message
,
171 UnitWriteFlags flags
,
172 sd_bus_error
*error
) {
181 r
= bus_cgroup_set_property(u
, &m
->cgroup_context
, name
, message
, flags
, error
);
185 if (u
->transient
&& u
->load_state
== UNIT_STUB
) {
186 /* This is a transient unit, let's load a little more */
188 r
= bus_mount_set_transient_property(m
, name
, message
, flags
, error
);
192 r
= bus_exec_context_set_transient_property(u
, &m
->exec_context
, name
, message
, flags
, error
);
196 r
= bus_kill_context_set_transient_property(u
, &m
->kill_context
, name
, message
, flags
, error
);
204 int bus_mount_commit_properties(Unit
*u
) {
207 unit_update_cgroup_members_masks(u
);
208 unit_realize_cgroup(u
);