Skip to content

Commit

Permalink
mount: allow default /proc mounts to be overridden though the command…
Browse files Browse the repository at this point in the history
… line
  • Loading branch information
Snaipe committed May 17, 2020
1 parent 46622ce commit 2a2ce8b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions enter.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ int enter(struct entry_settings *opts)
procfs one someone's oddball configuration. */
if (procst.st_dev != rootst.st_dev) {
const char *target = makepath("%s/proc", root);
umount2(target, MNT_DETACH);

if (mount("proc", target, "proc", 0, NULL) == -1) {
err(1, "mount(\"proc\", \"%s\", \"proc\", 0)", target);
}
Expand Down
10 changes: 10 additions & 0 deletions mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ void mount_entries(const char *root, const struct mount_entry *mounts, size_t nm
type = "tmpfs";
}

/* --mount options always override whatever default mounts we might have
done prior to calling mount_entries. This is done to avoid EBUSY when
mounting something with the same source and target as one of our
default mounts. Right now, the only case where this applies is the
automatic /proc remount. */
size_t targetlen = strlen(target);
if (strcmp(mnt->source, "proc") == 0 && strcmp(target + targetlen - 5, "/proc") == 0) {
umount2(target, MNT_DETACH);
}

if (mount(mnt->source, target, type, flags, mnt->options) == -1) {
err(1, "mount_entries: mount(\"%s\", \"%s\", \"%s\", %lu, \"%s\")",
mnt->source,
Expand Down

0 comments on commit 2a2ce8b

Please sign in to comment.