Skip to content

Commit

Permalink
sysroot: rework _ostree_sysroot_ensure_visible
Browse files Browse the repository at this point in the history
  • Loading branch information
ruihe774 committed Dec 19, 2024
1 parent f827879 commit 175a9e7
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/libostree/ostree-sysroot.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,27 +449,27 @@ _ostree_sysroot_ensure_visible (OstreeSysroot *self, GError **error)
/* Handle invisible sysroot */
if (invisible)
{
glnx_autofd int sysroot_ns_fd = open (OTCORE_RUN_OSTREE_PRIVATE "/sysroot-ns", O_RDONLY);
if (sysroot_ns_fd < 0)
glnx_autofd int sysroot_ns_fd = -1;
if (!glnx_openat_rdonly (AT_FDCWD, OTCORE_RUN_OSTREE_PRIVATE "/sysroot-ns", TRUE, &sysroot_ns_fd, error))
return FALSE;

g_autofree char *cur_ns = g_strdup_printf ("/proc/%d/ns/mnt", gettid ());
glnx_autofd int cur_ns_fd = open(cur_ns, O_RDONLY);
if (cur_ns_fd < 0)
glnx_autofd int cur_ns_fd = -1;
if (!glnx_openat_rdonly (AT_FDCWD, cur_ns, TRUE, &cur_ns_fd, error))
return FALSE;

if (setns (sysroot_ns_fd, CLONE_NEWNS) < 0)
return FALSE;
return glnx_throw_errno_prefix (error, "setns");

glnx_autofd int tree_fd = open_tree (AT_FDCWD, "/", OPEN_TREE_CLONE);
glnx_autofd int tree_fd = (int)syscall (SYS_open_tree, AT_FDCWD, "/", 1 /* OPEN_TREE_CLONE */ | O_CLOEXEC);
if (tree_fd < 0)
return FALSE;
return glnx_throw_errno_prefix (error, "open_tree");

if (setns (cur_ns_fd, CLONE_NEWNS) < 0)
abort (); // it's unsafe to continue if we cannot switch back

if (move_mount (tree_fd, "", AT_FDCWD, "/sysroot", MOVE_MOUNT_F_EMPTY_PATH) < 0)
return FALSE;
if (syscall (SYS_move_mount, tree_fd, "", AT_FDCWD, "/sysroot", 4 /* MOVE_MOUNT_F_EMPTY_PATH */) < 0)
return glnx_throw_errno_prefix (error, "move_mount");
}

/* Now close and reopen our file descriptors */
Expand Down

0 comments on commit 175a9e7

Please sign in to comment.