summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2015-06-01 12:46:13 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2015-06-01 12:46:13 +0000
commitf0a0a129f996e63981146d819eba425f85fd1eac (patch)
treefedf3fbd7cb87295b78ebef6166f48da441f7030
parent5d23708442b16138b800a4e4e9daf20eda50ba46 (diff)
downloadlinux-user-chroot-baserock/sam/improvements-for-sandboxlib.tar.gz
Allows mounting an in-memory temporary filesystem inside the chroot.
-rw-r--r--src/linux-user-chroot.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/linux-user-chroot.c b/src/linux-user-chroot.c
index 8b8700d..57089e8 100644
--- a/src/linux-user-chroot.c
+++ b/src/linux-user-chroot.c
@@ -92,7 +92,8 @@ fatal_errno (const char *message)
typedef enum {
MOUNT_SPEC_BIND,
MOUNT_SPEC_READONLY,
- MOUNT_SPEC_PROCFS
+ MOUNT_SPEC_PROCFS,
+ MOUNT_SPEC_TMPFS
} MountSpecType;
typedef struct _MountSpec MountSpec;
@@ -242,6 +243,22 @@ main (int argc,
bind_mounts = mount;
after_mount_arg_index += 2;
}
+ else if (strcmp (arg, "--mount-tmpfs") == 0)
+ {
+ MountSpec *mount;
+
+ if ((argc - after_mount_arg_index) < 2)
+ fatal ("--mount-tmpfs takes one argument");
+
+ mount = malloc (sizeof (MountSpec));
+ mount->type = MOUNT_SPEC_TMPFS;
+ mount->source = NULL;
+ mount->dest = argv[after_mount_arg_index+1];
+ mount->next = bind_mounts;
+
+ bind_mounts = mount;
+ after_mount_arg_index += 2;
+ }
else if (strcmp (arg, "--unshare-ipc") == 0)
{
unshare_ipc = 1;
@@ -272,7 +289,7 @@ main (int argc,
bind_mounts = reverse_mount_list (bind_mounts);
if ((argc - after_mount_arg_index) < 2)
- fatal ("usage: %s [--unshare-ipc] [--unshare-pid] [--unshare-net] [--mount-proc DIR] [--mount-readonly DIR] [--mount-bind SOURCE DEST] [--chdir DIR] ROOTDIR PROGRAM ARGS...", argv0);
+ fatal ("usage: %s [--unshare-ipc] [--unshare-pid] [--unshare-net] [--mount-proc DIR] [--mount-tmpfs DIR] [--mount-readonly DIR] [--mount-bind SOURCE DEST] [--chdir DIR] ROOTDIR PROGRAM ARGS...", argv0);
chroot_dir = argv[after_mount_arg_index];
program = argv[after_mount_arg_index+1];
program_argv = argv + after_mount_arg_index + 1;
@@ -375,6 +392,12 @@ main (int argc,
"proc", MS_MGC_VAL | MS_PRIVATE, NULL) < 0)
fatal_errno ("mount (\"proc\")");
}
+ else if (bind_mount_iter->type == MOUNT_SPEC_TMPFS)
+ {
+ if (mount ("none", dest,
+ "tmpfs", 0, NULL) < 0)
+ fatal_errno ("mount (\"tmpfs\")");
+ }
else
assert (0);
free (dest);