@@ -44,50 +44,17 @@ namespace android {
4444namespace init {
4545namespace {
4646
47- static bool BindMount (const std::string& source, const std::string& mount_point,
48- bool recursive = false ) {
49- unsigned long mountflags = MS_BIND;
50- if (recursive) {
51- mountflags |= MS_REC;
52- }
53- if (mount (source.c_str (), mount_point.c_str (), nullptr , mountflags, nullptr ) == -1 ) {
47+ static bool BindMount (const std::string& source, const std::string& mount_point) {
48+ if (mount (source.c_str (), mount_point.c_str (), nullptr , MS_BIND | MS_REC, nullptr ) == -1 ) {
5449 PLOG (ERROR) << " Failed to bind mount " << source;
5550 return false ;
5651 }
5752 return true ;
5853}
5954
60- static bool MakeShared (const std::string& mount_point, bool recursive = false ) {
61- unsigned long mountflags = MS_SHARED;
62- if (recursive) {
63- mountflags |= MS_REC;
64- }
65- if (mount (nullptr , mount_point.c_str (), nullptr , mountflags, nullptr ) == -1 ) {
66- PLOG (ERROR) << " Failed to change propagation type to shared" ;
67- return false ;
68- }
69- return true ;
70- }
71-
72- static bool MakeSlave (const std::string& mount_point, bool recursive = false ) {
73- unsigned long mountflags = MS_SLAVE;
74- if (recursive) {
75- mountflags |= MS_REC;
76- }
77- if (mount (nullptr , mount_point.c_str (), nullptr , mountflags, nullptr ) == -1 ) {
78- PLOG (ERROR) << " Failed to change propagation type to slave" ;
79- return false ;
80- }
81- return true ;
82- }
83-
84- static bool MakePrivate (const std::string& mount_point, bool recursive = false ) {
85- unsigned long mountflags = MS_PRIVATE;
86- if (recursive) {
87- mountflags |= MS_REC;
88- }
55+ static bool ChangeMount (const std::string& mount_point, unsigned long mountflags) {
8956 if (mount (nullptr , mount_point.c_str (), nullptr , mountflags, nullptr ) == -1 ) {
90- PLOG (ERROR) << " Failed to change propagation type to private " ;
57+ PLOG (ERROR) << " Failed to remount " << mount_point << " as " << std::hex << mountflags ;
9158 return false ;
9259 }
9360 return true ;
@@ -225,17 +192,17 @@ bool SetupMountNamespaces() {
225192 // needed for /foo/bar, then we will make /foo/bar as a mount point (by
226193 // bind-mounting by to itself) and set the propagation type of the mount
227194 // point to private.
228- if (!MakeShared (" /" , true /* recursive */ )) return false ;
195+ if (!ChangeMount (" /" , MS_SHARED | MS_REC )) return false ;
229196
230197 // /apex is a private mountpoint to give different sets of APEXes for
231198 // the bootstrap and default mount namespaces. The processes running with
232199 // the bootstrap namespace get APEXes from the read-only partition.
233- if (!(MakePrivate (" /apex" ))) return false ;
200+ if (!(ChangeMount (" /apex" , MS_PRIVATE ))) return false ;
234201
235202 // /linkerconfig is a private mountpoint to give a different linker configuration
236203 // based on the mount namespace. Subdirectory will be bind-mounted based on current mount
237204 // namespace
238- if (!(MakePrivate (" /linkerconfig" ))) return false ;
205+ if (!(ChangeMount (" /linkerconfig" , MS_PRIVATE ))) return false ;
239206
240207 // The two mount namespaces present challenges for scoped storage, because
241208 // vold, which is responsible for most of the mounting, lives in the
@@ -266,15 +233,15 @@ bool SetupMountNamespaces() {
266233 if (!mkdir_recursive (" /mnt/user" , 0755 )) return false ;
267234 if (!mkdir_recursive (" /mnt/installer" , 0755 )) return false ;
268235 if (!mkdir_recursive (" /mnt/androidwritable" , 0755 )) return false ;
269- if (!(BindMount (" /mnt/user" , " /mnt/installer" , true ))) return false ;
270- if (!(BindMount (" /mnt/user" , " /mnt/androidwritable" , true ))) return false ;
236+ if (!(BindMount (" /mnt/user" , " /mnt/installer" ))) return false ;
237+ if (!(BindMount (" /mnt/user" , " /mnt/androidwritable" ))) return false ;
271238 // First, make /mnt/installer and /mnt/androidwritable a slave bind mount
272- if (!(MakeSlave (" /mnt/installer" ))) return false ;
273- if (!(MakeSlave (" /mnt/androidwritable" ))) return false ;
239+ if (!(ChangeMount (" /mnt/installer" , MS_SLAVE ))) return false ;
240+ if (!(ChangeMount (" /mnt/androidwritable" , MS_SLAVE ))) return false ;
274241 // Then, make it shared again - effectively creating a new peer group, that
275242 // will be inherited by new mount namespaces.
276- if (!(MakeShared (" /mnt/installer" ))) return false ;
277- if (!(MakeShared (" /mnt/androidwritable" ))) return false ;
243+ if (!(ChangeMount (" /mnt/installer" , MS_SHARED ))) return false ;
244+ if (!(ChangeMount (" /mnt/androidwritable" , MS_SHARED ))) return false ;
278245
279246 bootstrap_ns_fd.reset (OpenMountNamespace ());
280247 bootstrap_ns_id = GetMountNamespaceId ();
0 commit comments