Line data Source code
1 : /* SPDX-License-Identifier: LGPL-2.1+ */
2 :
3 : #include "bus-util.h"
4 : #include "dbus-cgroup.h"
5 : #include "dbus-execute.h"
6 : #include "dbus-kill.h"
7 : #include "dbus-mount.h"
8 : #include "dbus-util.h"
9 : #include "mount.h"
10 : #include "string-util.h"
11 : #include "unit.h"
12 :
13 0 : static const char *mount_get_what(const Mount *m) {
14 0 : if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.what)
15 0 : return m->parameters_proc_self_mountinfo.what;
16 0 : if (m->from_fragment && m->parameters_fragment.what)
17 0 : return m->parameters_fragment.what;
18 0 : return NULL;
19 : }
20 :
21 0 : static const char *mount_get_options(const Mount *m) {
22 0 : if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.options)
23 0 : return m->parameters_proc_self_mountinfo.options;
24 0 : if (m->from_fragment && m->parameters_fragment.options)
25 0 : return m->parameters_fragment.options;
26 0 : return NULL;
27 : }
28 :
29 0 : static const char *mount_get_fstype(const Mount *m) {
30 0 : if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.fstype)
31 0 : return m->parameters_proc_self_mountinfo.fstype;
32 0 : else if (m->from_fragment && m->parameters_fragment.fstype)
33 0 : return m->parameters_fragment.fstype;
34 0 : return NULL;
35 : }
36 :
37 0 : static BUS_DEFINE_PROPERTY_GET(property_get_what, "s", Mount, mount_get_what);
38 0 : static BUS_DEFINE_PROPERTY_GET(property_get_options, "s", Mount, mount_get_options);
39 0 : static BUS_DEFINE_PROPERTY_GET(property_get_type, "s", Mount, mount_get_fstype);
40 0 : static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, mount_result, MountResult);
41 :
42 : const sd_bus_vtable bus_mount_vtable[] = {
43 : SD_BUS_VTABLE_START(0),
44 : SD_BUS_PROPERTY("Where", "s", NULL, offsetof(Mount, where), SD_BUS_VTABLE_PROPERTY_CONST),
45 : SD_BUS_PROPERTY("What", "s", property_get_what, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
46 : SD_BUS_PROPERTY("Options","s", property_get_options, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
47 : SD_BUS_PROPERTY("Type", "s", property_get_type, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
48 : SD_BUS_PROPERTY("TimeoutUSec", "t", bus_property_get_usec, offsetof(Mount, timeout_usec), SD_BUS_VTABLE_PROPERTY_CONST),
49 : SD_BUS_PROPERTY("ControlPID", "u", bus_property_get_pid, offsetof(Mount, control_pid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
50 : SD_BUS_PROPERTY("DirectoryMode", "u", bus_property_get_mode, offsetof(Mount, directory_mode), SD_BUS_VTABLE_PROPERTY_CONST),
51 : SD_BUS_PROPERTY("SloppyOptions", "b", bus_property_get_bool, offsetof(Mount, sloppy_options), SD_BUS_VTABLE_PROPERTY_CONST),
52 : SD_BUS_PROPERTY("LazyUnmount", "b", bus_property_get_bool, offsetof(Mount, lazy_unmount), SD_BUS_VTABLE_PROPERTY_CONST),
53 : SD_BUS_PROPERTY("ForceUnmount", "b", bus_property_get_bool, offsetof(Mount, force_unmount), SD_BUS_VTABLE_PROPERTY_CONST),
54 : SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Mount, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
55 : SD_BUS_PROPERTY("UID", "u", bus_property_get_uid, offsetof(Unit, ref_uid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
56 : SD_BUS_PROPERTY("GID", "u", bus_property_get_gid, offsetof(Unit, ref_gid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
57 : BUS_EXEC_COMMAND_VTABLE("ExecMount", offsetof(Mount, exec_command[MOUNT_EXEC_MOUNT]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
58 : BUS_EXEC_COMMAND_VTABLE("ExecUnmount", offsetof(Mount, exec_command[MOUNT_EXEC_UNMOUNT]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
59 : BUS_EXEC_COMMAND_VTABLE("ExecRemount", offsetof(Mount, exec_command[MOUNT_EXEC_REMOUNT]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
60 : SD_BUS_VTABLE_END
61 : };
62 :
63 0 : static int bus_mount_set_transient_property(
64 : Mount *m,
65 : const char *name,
66 : sd_bus_message *message,
67 : UnitWriteFlags flags,
68 : sd_bus_error *error) {
69 :
70 0 : Unit *u = UNIT(m);
71 :
72 0 : assert(m);
73 0 : assert(name);
74 0 : assert(message);
75 :
76 0 : flags |= UNIT_PRIVATE;
77 :
78 0 : if (streq(name, "Where"))
79 0 : return bus_set_transient_path(u, name, &m->where, message, flags, error);
80 :
81 0 : if (streq(name, "What"))
82 0 : return bus_set_transient_string(u, name, &m->parameters_fragment.what, message, flags, error);
83 :
84 0 : if (streq(name, "Options"))
85 0 : return bus_set_transient_string(u, name, &m->parameters_fragment.options, message, flags, error);
86 :
87 0 : if (streq(name, "Type"))
88 0 : return bus_set_transient_string(u, name, &m->parameters_fragment.fstype, message, flags, error);
89 :
90 0 : if (streq(name, "TimeoutUSec"))
91 0 : return bus_set_transient_usec_fix_0(u, name, &m->timeout_usec, message, flags, error);
92 :
93 0 : if (streq(name, "DirectoryMode"))
94 0 : return bus_set_transient_mode_t(u, name, &m->directory_mode, message, flags, error);
95 :
96 0 : if (streq(name, "SloppyOptions"))
97 0 : return bus_set_transient_bool(u, name, &m->sloppy_options, message, flags, error);
98 :
99 0 : if (streq(name, "LazyUnmount"))
100 0 : return bus_set_transient_bool(u, name, &m->lazy_unmount, message, flags, error);
101 :
102 0 : if (streq(name, "ForceUnmount"))
103 0 : return bus_set_transient_bool(u, name, &m->force_unmount, message, flags, error);
104 :
105 0 : return 0;
106 : }
107 :
108 0 : int bus_mount_set_property(
109 : Unit *u,
110 : const char *name,
111 : sd_bus_message *message,
112 : UnitWriteFlags flags,
113 : sd_bus_error *error) {
114 :
115 0 : Mount *m = MOUNT(u);
116 : int r;
117 :
118 0 : assert(m);
119 0 : assert(name);
120 0 : assert(message);
121 :
122 0 : r = bus_cgroup_set_property(u, &m->cgroup_context, name, message, flags, error);
123 0 : if (r != 0)
124 0 : return r;
125 :
126 0 : if (u->transient && u->load_state == UNIT_STUB) {
127 : /* This is a transient unit, let's load a little more */
128 :
129 0 : r = bus_mount_set_transient_property(m, name, message, flags, error);
130 0 : if (r != 0)
131 0 : return r;
132 :
133 0 : r = bus_exec_context_set_transient_property(u, &m->exec_context, name, message, flags, error);
134 0 : if (r != 0)
135 0 : return r;
136 :
137 0 : r = bus_kill_context_set_transient_property(u, &m->kill_context, name, message, flags, error);
138 0 : if (r != 0)
139 0 : return r;
140 : }
141 :
142 0 : return 0;
143 : }
144 :
145 0 : int bus_mount_commit_properties(Unit *u) {
146 0 : assert(u);
147 :
148 0 : unit_invalidate_cgroup_members_masks(u);
149 0 : unit_realize_cgroup(u);
150 :
151 0 : return 0;
152 : }
|