xbps-uchroot: added -o <opts> to pass options to the temporary tmpfs mount.

This commit is contained in:
Juan RP 2015-04-20 20:44:42 +02:00
parent 7ea5a53cbd
commit 31bf6c5309
3 changed files with 25 additions and 10 deletions

4
NEWS
View File

@ -1,5 +1,9 @@
xbps-0.45 (???): 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 * libxbps: file descripters are now opened with O_CLOEXEC, to avoid warnings
of leaked file descriptors while running package install/remove scripts. of leaked file descriptors while running package install/remove scripts.

View File

@ -28,9 +28,9 @@
* specifically for xbps-src use: * specifically for xbps-src use:
* *
* - This bind mounts exactly what we need, no support for additional mounts. * - 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. * - 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 #define _GNU_SOURCE
#include <sys/types.h> #include <sys/types.h>
@ -94,7 +94,7 @@ cleanup_overlayfs(void)
static void __attribute__((noreturn)) static void __attribute__((noreturn))
usage(const char *p) usage(const char *p)
{ {
printf("Usage: %s [-D dir] [-H dir] [-S dir] [-O] <chrootdir> <command>\n\n" printf("Usage: %s [-D dir] [-H dir] [-S dir] [-O -o <opts>] <chrootdir> <command>\n\n"
"-D <distdir> Directory to be bind mounted at <chrootdir>/void-packages\n" "-D <distdir> Directory to be bind mounted at <chrootdir>/void-packages\n"
"-H <hostdir> Directory to be bind mounted at <chrootdir>/host\n" "-H <hostdir> Directory to be bind mounted at <chrootdir>/host\n"
"-S <shmdir> Directory to be bind mounted at <chrootdir>/<shmdir>\n", p); "-S <shmdir> Directory to be bind mounted at <chrootdir>/<shmdir>\n", p);
@ -139,14 +139,15 @@ bindmount(uid_t ruid, const char *chrootdir, const char *dir, const char *dest)
} }
static char * 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; char *upperdir, *workdir, *newchrootdir, *mopts;
const void *opts; const void *opts = NULL;
/* /*
* Create a temporary directory on tmpfs for overlayfs storage. * 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); die("failed to mount tmpfs on %s", tmpdir);
/* /*
* Create the upper/work dirs to setup overlayfs. * Create the upper/work dirs to setup overlayfs.
@ -185,13 +186,13 @@ main(int argc, char **argv)
{ {
uid_t ruid, euid, suid; uid_t ruid, euid, suid;
gid_t rgid, egid, sgid; 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]; char **cmdargs, *b, mountdir[PATH_MAX-1];
int aidx = 0, clone_flags, child_status = 0; int aidx = 0, clone_flags, child_status = 0;
pid_t child; pid_t child;
bool overlayfs = false; bool overlayfs = false;
chrootdir = distdir = hostdir = shmdir = cmd = NULL; tmpfs_opts = chrootdir = distdir = hostdir = shmdir = cmd = NULL;
argv0 = argv[0]; argv0 = argv[0];
argc--; argc--;
argv++; argv++;
@ -204,6 +205,10 @@ main(int argc, char **argv)
/* use overlayfs */ /* use overlayfs */
overlayfs = true; overlayfs = true;
aidx++; 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) { } else if (strcmp(argv[aidx], "-D") == 0) {
/* distdir */ /* distdir */
distdir = argv[aidx+1]; distdir = argv[aidx+1];
@ -271,7 +276,7 @@ main(int argc, char **argv)
} }
/* setup our overlayfs if set */ /* setup our overlayfs if set */
if (overlayfs) if (overlayfs)
chrootdir = setup_overlayfs(chrootdir, ruid, rgid); chrootdir = setup_overlayfs(chrootdir, ruid, rgid, tmpfs_opts);
/* mount /proc */ /* mount /proc */
snprintf(mountdir, sizeof(mountdir), "%s/proc", chrootdir); snprintf(mountdir, sizeof(mountdir), "%s/proc", chrootdir);

View File

@ -1,4 +1,4 @@
.Dd March 26, 2014 .Dd April 20, 2014
.Dt XBPS-UCHROOT 8 .Dt XBPS-UCHROOT 8
.Sh NAME .Sh NAME
.Nm xbps-uchroot .Nm xbps-uchroot
@ -42,6 +42,12 @@ use it, otherwise use
Setups a temporary directory mounted on tmpfs and then creates an overlay layer 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 (via overlayfs) with the lowerdir set to CHROOTDIR. Useful to create a temporary
tree that does not preserve changes in CHROOTDIR. 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 .El
.Sh SECURITY .Sh SECURITY
The The