Skip to content

Commit

Permalink
main: Unconditionally set up mount namespace
Browse files Browse the repository at this point in the history
I was being very conservative initially here, but I think it's
really safe to just unconditionally set up the mount namespace.

This avoids having to check twice for a read-only `/sysroot`
(once in the binary and once in the library).
  • Loading branch information
cgwalters committed Jan 10, 2021
1 parent fd9d422 commit 10556a9
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions src/ostree/ot-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,26 +122,10 @@ maybe_setup_mount_namespace (gboolean *out_ns,
if (errno == ENOENT)
return TRUE;

glnx_autofd int sysroot_subdir_fd = glnx_opendirat_with_errno (AT_FDCWD, "/sysroot", TRUE);
if (sysroot_subdir_fd < 0)
{
if (errno != ENOENT)
return glnx_throw_errno_prefix (error, "opendirat");
/* No /sysroot - nothing to do */
return TRUE;
}

struct statvfs stvfs;
if (fstatvfs (sysroot_subdir_fd, &stvfs) < 0)
return glnx_throw_errno_prefix (error, "fstatvfs");
if (stvfs.f_flag & ST_RDONLY)
{
if (unshare (CLONE_NEWNS) < 0)
return glnx_throw_errno_prefix (error, "preparing writable sysroot: unshare (CLONE_NEWNS)");

*out_ns = TRUE;
}
if (unshare (CLONE_NEWNS) < 0)
return glnx_throw_errno_prefix (error, "setting up mount namespace: unshare(CLONE_NEWNS)");

*out_ns = TRUE;
return TRUE;
}

Expand Down

0 comments on commit 10556a9

Please sign in to comment.