}
int detach_mount_namespace(void) {
-
- /* Detaches the mount namespace, disabling propagation from our namespace to the host */
+ /* Detaches the mount namespace, disabling propagation from our namespace to the host. Sets
+ * propagation first to MS_SLAVE for all mounts (disabling propagation), and then back to MS_SHARED
+ * (so that we create a new peer group). */
if (unshare(CLONE_NEWNS) < 0)
- return -errno;
+ return log_debug_errno(errno, "Failed to acquire mount namespace: %m");
+
+ if (mount(NULL, "/", NULL, MS_SLAVE | MS_REC, NULL) < 0)
+ return log_debug_errno(errno, "Failed to set mount propagation to MS_SLAVE for all mounts: %m");
- return RET_NERRNO(mount(NULL, "/", NULL, MS_SLAVE | MS_REC, NULL));
+ if (mount(NULL, "/", NULL, MS_SHARED | MS_REC, NULL) < 0)
+ return log_debug_errno(errno, "Failed to set mount propagation back to MS_SHARED for all mounts: %m");
+
+ return 0;
}
int userns_acquire(const char *uid_map, const char *gid_map) {