From 31bf6c530942baa90930b40507b86ed943282753 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Mon, 20 Apr 2015 20:44:42 +0200 Subject: [PATCH] xbps-uchroot: added -o to pass options to the temporary tmpfs mount. --- NEWS | 4 ++++ bin/xbps-uchroot/main.c | 23 ++++++++++++++--------- bin/xbps-uchroot/xbps-uchroot.8 | 8 +++++++- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index 66cf5afd..d5ad4ea2 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,9 @@ xbps-0.45 (???): + * xbps-uchroot(8): added -o option to pass arguments to the tmpfs mount, + as is. See mount(8). Useful to specify a size for the temporary tmpfs + with overlayfs (-O). + * libxbps: file descripters are now opened with O_CLOEXEC, to avoid warnings of leaked file descriptors while running package install/remove scripts. diff --git a/bin/xbps-uchroot/main.c b/bin/xbps-uchroot/main.c index 18ce7f65..a9800b53 100644 --- a/bin/xbps-uchroot/main.c +++ b/bin/xbps-uchroot/main.c @@ -28,9 +28,9 @@ * specifically for xbps-src use: * * - This bind mounts exactly what we need, no support for additional mounts. - * - This uses IPC/PID/mount namespaces, nothing more. + * - This uses IPC/PID/UTS namespaces, nothing more. * - Disables namespace features if running in OpenVZ containers. - * - Supports overlayfs on a tmpfs mounted directory. + * - Supports overlayfs on a temporary tmpfs mounted directory. */ #define _GNU_SOURCE #include @@ -94,7 +94,7 @@ cleanup_overlayfs(void) static void __attribute__((noreturn)) usage(const char *p) { - printf("Usage: %s [-D dir] [-H dir] [-S dir] [-O] \n\n" + printf("Usage: %s [-D dir] [-H dir] [-S dir] [-O -o ] \n\n" "-D Directory to be bind mounted at /void-packages\n" "-H Directory to be bind mounted at /host\n" "-S Directory to be bind mounted at /\n", p); @@ -139,14 +139,15 @@ bindmount(uid_t ruid, const char *chrootdir, const char *dir, const char *dest) } static char * -setup_overlayfs(const char *chrootdir, uid_t ruid, gid_t rgid) +setup_overlayfs(const char *chrootdir, uid_t ruid, gid_t rgid, const char *tmpfs_opts) { char *upperdir, *workdir, *newchrootdir, *mopts; - const void *opts; + const void *opts = NULL; /* * Create a temporary directory on tmpfs for overlayfs storage. */ - if (mount("tmpfs", tmpdir, "tmpfs", 0, NULL) == -1) + opts = tmpfs_opts; + if (mount("tmpfs", tmpdir, "tmpfs", 0, opts) == -1) die("failed to mount tmpfs on %s", tmpdir); /* * Create the upper/work dirs to setup overlayfs. @@ -185,13 +186,13 @@ main(int argc, char **argv) { uid_t ruid, euid, suid; gid_t rgid, egid, sgid; - const char *chrootdir, *distdir, *hostdir, *shmdir, *cmd, *argv0; + const char *chrootdir, *distdir, *hostdir, *shmdir, *tmpfs_opts, *cmd, *argv0; char **cmdargs, *b, mountdir[PATH_MAX-1]; int aidx = 0, clone_flags, child_status = 0; pid_t child; bool overlayfs = false; - chrootdir = distdir = hostdir = shmdir = cmd = NULL; + tmpfs_opts = chrootdir = distdir = hostdir = shmdir = cmd = NULL; argv0 = argv[0]; argc--; argv++; @@ -204,6 +205,10 @@ main(int argc, char **argv) /* use overlayfs */ overlayfs = true; aidx++; + } else if (strcmp(argv[aidx], "-o") == 0) { + /* tmpfs args with overlayfs */ + tmpfs_opts = argv[aidx+1]; + aidx += 2; } else if (strcmp(argv[aidx], "-D") == 0) { /* distdir */ distdir = argv[aidx+1]; @@ -271,7 +276,7 @@ main(int argc, char **argv) } /* setup our overlayfs if set */ if (overlayfs) - chrootdir = setup_overlayfs(chrootdir, ruid, rgid); + chrootdir = setup_overlayfs(chrootdir, ruid, rgid, tmpfs_opts); /* mount /proc */ snprintf(mountdir, sizeof(mountdir), "%s/proc", chrootdir); diff --git a/bin/xbps-uchroot/xbps-uchroot.8 b/bin/xbps-uchroot/xbps-uchroot.8 index 07021dcd..fc78d477 100644 --- a/bin/xbps-uchroot/xbps-uchroot.8 +++ b/bin/xbps-uchroot/xbps-uchroot.8 @@ -1,4 +1,4 @@ -.Dd March 26, 2014 +.Dd April 20, 2014 .Dt XBPS-UCHROOT 8 .Sh NAME .Nm xbps-uchroot @@ -42,6 +42,12 @@ use it, otherwise use Setups a temporary directory mounted on tmpfs and then creates an overlay layer (via overlayfs) with the lowerdir set to CHROOTDIR. Useful to create a temporary tree that does not preserve changes in CHROOTDIR. +.It Fl o Ar opts +Arguments passed to the tmpfs mount, if the +.Fl O +option is specified. +This expects the same arguments that are accepted as options in tmpfs, as explained in +.Xr mount 8 . .El .Sh SECURITY The