1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2010 Lennart Poettering
9 #include "dbus-cgroup.h"
10 #include "dbus-execute.h"
11 #include "dbus-kill.h"
12 #include "dbus-mount.h"
13 #include "dbus-util.h"
15 #include "string-util.h"
18 static int property_get_what(
21 const char *interface
,
23 sd_bus_message
*reply
,
25 sd_bus_error
*error
) {
34 if (m
->from_proc_self_mountinfo
&& m
->parameters_proc_self_mountinfo
.what
)
35 d
= m
->parameters_proc_self_mountinfo
.what
;
36 else if (m
->from_fragment
&& m
->parameters_fragment
.what
)
37 d
= m
->parameters_fragment
.what
;
39 return sd_bus_message_append(reply
, "s", d
);
42 static int property_get_options(
45 const char *interface
,
47 sd_bus_message
*reply
,
49 sd_bus_error
*error
) {
58 if (m
->from_proc_self_mountinfo
&& m
->parameters_proc_self_mountinfo
.options
)
59 d
= m
->parameters_proc_self_mountinfo
.options
;
60 else if (m
->from_fragment
&& m
->parameters_fragment
.options
)
61 d
= m
->parameters_fragment
.options
;
63 return sd_bus_message_append(reply
, "s", d
);
66 static int property_get_type(
69 const char *interface
,
71 sd_bus_message
*reply
,
73 sd_bus_error
*error
) {
75 const char *fstype
= NULL
;
82 if (m
->from_proc_self_mountinfo
&& m
->parameters_proc_self_mountinfo
.fstype
)
83 fstype
= m
->parameters_proc_self_mountinfo
.fstype
;
84 else if (m
->from_fragment
&& m
->parameters_fragment
.fstype
)
85 fstype
= m
->parameters_fragment
.fstype
;
87 return sd_bus_message_append(reply
, "s", fstype
);
90 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result
, mount_result
, MountResult
);
92 const sd_bus_vtable bus_mount_vtable
[] = {
93 SD_BUS_VTABLE_START(0),
94 SD_BUS_PROPERTY("Where", "s", NULL
, offsetof(Mount
, where
), SD_BUS_VTABLE_PROPERTY_CONST
),
95 SD_BUS_PROPERTY("What", "s", property_get_what
, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
96 SD_BUS_PROPERTY("Options","s", property_get_options
, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
97 SD_BUS_PROPERTY("Type", "s", property_get_type
, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
98 SD_BUS_PROPERTY("TimeoutUSec", "t", bus_property_get_usec
, offsetof(Mount
, timeout_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
99 SD_BUS_PROPERTY("ControlPID", "u", bus_property_get_pid
, offsetof(Mount
, control_pid
), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
100 SD_BUS_PROPERTY("DirectoryMode", "u", bus_property_get_mode
, offsetof(Mount
, directory_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
101 SD_BUS_PROPERTY("SloppyOptions", "b", bus_property_get_bool
, offsetof(Mount
, sloppy_options
), SD_BUS_VTABLE_PROPERTY_CONST
),
102 SD_BUS_PROPERTY("LazyUnmount", "b", bus_property_get_bool
, offsetof(Mount
, lazy_unmount
), SD_BUS_VTABLE_PROPERTY_CONST
),
103 SD_BUS_PROPERTY("ForceUnmount", "b", bus_property_get_bool
, offsetof(Mount
, force_unmount
), SD_BUS_VTABLE_PROPERTY_CONST
),
104 SD_BUS_PROPERTY("Result", "s", property_get_result
, offsetof(Mount
, result
), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
105 SD_BUS_PROPERTY("UID", "u", NULL
, offsetof(Unit
, ref_uid
), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
106 SD_BUS_PROPERTY("GID", "u", NULL
, offsetof(Unit
, ref_gid
), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
107 BUS_EXEC_COMMAND_VTABLE("ExecMount", offsetof(Mount
, exec_command
[MOUNT_EXEC_MOUNT
]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION
),
108 BUS_EXEC_COMMAND_VTABLE("ExecUnmount", offsetof(Mount
, exec_command
[MOUNT_EXEC_UNMOUNT
]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION
),
109 BUS_EXEC_COMMAND_VTABLE("ExecRemount", offsetof(Mount
, exec_command
[MOUNT_EXEC_REMOUNT
]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION
),
113 static int bus_mount_set_transient_property(
116 sd_bus_message
*message
,
117 UnitWriteFlags flags
,
118 sd_bus_error
*error
) {
126 flags
|= UNIT_PRIVATE
;
128 if (streq(name
, "Where"))
129 return bus_set_transient_path(u
, name
, &m
->where
, message
, flags
, error
);
131 if (streq(name
, "What"))
132 return bus_set_transient_string(u
, name
, &m
->parameters_fragment
.what
, message
, flags
, error
);
134 if (streq(name
, "Options"))
135 return bus_set_transient_string(u
, name
, &m
->parameters_fragment
.options
, message
, flags
, error
);
137 if (streq(name
, "Type"))
138 return bus_set_transient_string(u
, name
, &m
->parameters_fragment
.fstype
, message
, flags
, error
);
140 if (streq(name
, "TimeoutUSec"))
141 return bus_set_transient_usec_fix_0(u
, name
, &m
->timeout_usec
, message
, flags
, error
);
143 if (streq(name
, "DirectoryMode"))
144 return bus_set_transient_mode_t(u
, name
, &m
->directory_mode
, message
, flags
, error
);
146 if (streq(name
, "SloppyOptions"))
147 return bus_set_transient_bool(u
, name
, &m
->sloppy_options
, message
, flags
, error
);
149 if (streq(name
, "LazyUnmount"))
150 return bus_set_transient_bool(u
, name
, &m
->lazy_unmount
, message
, flags
, error
);
152 if (streq(name
, "ForceUnmount"))
153 return bus_set_transient_bool(u
, name
, &m
->force_unmount
, message
, flags
, error
);
158 int bus_mount_set_property(
161 sd_bus_message
*message
,
162 UnitWriteFlags flags
,
163 sd_bus_error
*error
) {
172 r
= bus_cgroup_set_property(u
, &m
->cgroup_context
, name
, message
, flags
, error
);
176 if (u
->transient
&& u
->load_state
== UNIT_STUB
) {
177 /* This is a transient unit, let's load a little more */
179 r
= bus_mount_set_transient_property(m
, name
, message
, flags
, error
);
183 r
= bus_exec_context_set_transient_property(u
, &m
->exec_context
, name
, message
, flags
, error
);
187 r
= bus_kill_context_set_transient_property(u
, &m
->kill_context
, name
, message
, flags
, error
);
195 int bus_mount_commit_properties(Unit
*u
) {
198 unit_update_cgroup_members_masks(u
);
199 unit_realize_cgroup(u
);