1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 #include "bus-get-properties.h"
4 #include "dbus-cgroup.h"
5 #include "dbus-execute.h"
7 #include "dbus-mount.h"
10 #include "string-util.h"
14 static int property_get_what(
17 const char *interface
,
19 sd_bus_message
*reply
,
21 sd_bus_error
*error
) {
23 _cleanup_free_
char *escaped
= NULL
;
24 Mount
*m
= ASSERT_PTR(userdata
);
30 if (m
->from_proc_self_mountinfo
&& m
->parameters_proc_self_mountinfo
.what
)
31 s
= m
->parameters_proc_self_mountinfo
.what
;
32 else if (m
->from_fragment
&& m
->parameters_fragment
.what
)
33 s
= m
->parameters_fragment
.what
;
36 escaped
= utf8_escape_invalid(s
);
41 return sd_bus_message_append_basic(reply
, 's', escaped
);
44 static int property_get_options(
47 const char *interface
,
49 sd_bus_message
*reply
,
51 sd_bus_error
*error
) {
53 _cleanup_free_
char *escaped
= NULL
;
54 Mount
*m
= ASSERT_PTR(userdata
);
60 if (m
->from_proc_self_mountinfo
&& m
->parameters_proc_self_mountinfo
.options
)
61 s
= m
->parameters_proc_self_mountinfo
.options
;
62 else if (m
->from_fragment
&& m
->parameters_fragment
.options
)
63 s
= m
->parameters_fragment
.options
;
66 escaped
= utf8_escape_invalid(s
);
71 return sd_bus_message_append_basic(reply
, 's', escaped
);
74 static const char *mount_get_fstype(const Mount
*m
) {
75 if (m
->from_proc_self_mountinfo
&& m
->parameters_proc_self_mountinfo
.fstype
)
76 return m
->parameters_proc_self_mountinfo
.fstype
;
77 else if (m
->from_fragment
&& m
->parameters_fragment
.fstype
)
78 return m
->parameters_fragment
.fstype
;
82 static BUS_DEFINE_PROPERTY_GET(property_get_type
, "s", Mount
, mount_get_fstype
);
83 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result
, mount_result
, MountResult
);
85 const sd_bus_vtable bus_mount_vtable
[] = {
86 SD_BUS_VTABLE_START(0),
87 SD_BUS_PROPERTY("Where", "s", NULL
, offsetof(Mount
, where
), SD_BUS_VTABLE_PROPERTY_CONST
),
88 SD_BUS_PROPERTY("What", "s", property_get_what
, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
89 SD_BUS_PROPERTY("Options","s", property_get_options
, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
90 SD_BUS_PROPERTY("Type", "s", property_get_type
, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
91 SD_BUS_PROPERTY("TimeoutUSec", "t", bus_property_get_usec
, offsetof(Mount
, timeout_usec
), SD_BUS_VTABLE_PROPERTY_CONST
),
92 SD_BUS_PROPERTY("ControlPID", "u", bus_property_get_pid
, offsetof(Mount
, control_pid
), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
93 SD_BUS_PROPERTY("DirectoryMode", "u", bus_property_get_mode
, offsetof(Mount
, directory_mode
), SD_BUS_VTABLE_PROPERTY_CONST
),
94 SD_BUS_PROPERTY("SloppyOptions", "b", bus_property_get_bool
, offsetof(Mount
, sloppy_options
), SD_BUS_VTABLE_PROPERTY_CONST
),
95 SD_BUS_PROPERTY("LazyUnmount", "b", bus_property_get_bool
, offsetof(Mount
, lazy_unmount
), SD_BUS_VTABLE_PROPERTY_CONST
),
96 SD_BUS_PROPERTY("ForceUnmount", "b", bus_property_get_bool
, offsetof(Mount
, force_unmount
), SD_BUS_VTABLE_PROPERTY_CONST
),
97 SD_BUS_PROPERTY("ReadWriteOnly", "b", bus_property_get_bool
, offsetof(Mount
, read_write_only
), SD_BUS_VTABLE_PROPERTY_CONST
),
98 SD_BUS_PROPERTY("Result", "s", property_get_result
, offsetof(Mount
, result
), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
99 SD_BUS_PROPERTY("UID", "u", bus_property_get_uid
, offsetof(Unit
, ref_uid
), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
100 SD_BUS_PROPERTY("GID", "u", bus_property_get_gid
, offsetof(Unit
, ref_gid
), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
101 BUS_EXEC_COMMAND_VTABLE("ExecMount", offsetof(Mount
, exec_command
[MOUNT_EXEC_MOUNT
]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION
),
102 BUS_EXEC_COMMAND_VTABLE("ExecUnmount", offsetof(Mount
, exec_command
[MOUNT_EXEC_UNMOUNT
]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION
),
103 BUS_EXEC_COMMAND_VTABLE("ExecRemount", offsetof(Mount
, exec_command
[MOUNT_EXEC_REMOUNT
]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION
),
107 static int bus_mount_set_transient_property(
110 sd_bus_message
*message
,
111 UnitWriteFlags flags
,
112 sd_bus_error
*error
) {
120 flags
|= UNIT_PRIVATE
;
122 if (streq(name
, "Where"))
123 return bus_set_transient_path(u
, name
, &m
->where
, message
, flags
, error
);
125 if (streq(name
, "What"))
126 return bus_set_transient_string(u
, name
, &m
->parameters_fragment
.what
, message
, flags
, error
);
128 if (streq(name
, "Options"))
129 return bus_set_transient_string(u
, name
, &m
->parameters_fragment
.options
, message
, flags
, error
);
131 if (streq(name
, "Type"))
132 return bus_set_transient_string(u
, name
, &m
->parameters_fragment
.fstype
, message
, flags
, error
);
134 if (streq(name
, "TimeoutUSec"))
135 return bus_set_transient_usec_fix_0(u
, name
, &m
->timeout_usec
, message
, flags
, error
);
137 if (streq(name
, "DirectoryMode"))
138 return bus_set_transient_mode_t(u
, name
, &m
->directory_mode
, message
, flags
, error
);
140 if (streq(name
, "SloppyOptions"))
141 return bus_set_transient_bool(u
, name
, &m
->sloppy_options
, message
, flags
, error
);
143 if (streq(name
, "LazyUnmount"))
144 return bus_set_transient_bool(u
, name
, &m
->lazy_unmount
, message
, flags
, error
);
146 if (streq(name
, "ForceUnmount"))
147 return bus_set_transient_bool(u
, name
, &m
->force_unmount
, message
, flags
, error
);
149 if (streq(name
, "ReadWriteOnly"))
150 return bus_set_transient_bool(u
, name
, &m
->read_write_only
, message
, flags
, error
);
155 int bus_mount_set_property(
158 sd_bus_message
*message
,
159 UnitWriteFlags flags
,
160 sd_bus_error
*error
) {
169 r
= bus_cgroup_set_property(u
, &m
->cgroup_context
, name
, message
, flags
, error
);
173 if (u
->transient
&& u
->load_state
== UNIT_STUB
) {
174 /* This is a transient unit, let's load a little more */
176 r
= bus_mount_set_transient_property(m
, name
, message
, flags
, error
);
180 r
= bus_exec_context_set_transient_property(u
, &m
->exec_context
, name
, message
, flags
, error
);
184 r
= bus_kill_context_set_transient_property(u
, &m
->kill_context
, name
, message
, flags
, error
);
192 int bus_mount_commit_properties(Unit
*u
) {
195 unit_realize_cgroup(u
);