From: Christian Brauner Date: Thu, 23 Aug 2018 21:11:13 +0000 (+0200) Subject: lxc-unshare: add missing declaration X-Git-Tag: lxc-2.0.10~153 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=37b143df7d8ed9aaec8c1fbecdd24256633af946;p=thirdparty%2Flxc.git lxc-unshare: add missing declaration Signed-off-by: Christian Brauner --- diff --git a/src/lxc/initutils.h b/src/lxc/initutils.h index ec44554e3..b815cd194 100644 --- a/src/lxc/initutils.h +++ b/src/lxc/initutils.h @@ -68,7 +68,6 @@ struct prctl_mm_map { }; #endif -extern void lxc_setup_fs(void); extern const char *lxc_global_config_value(const char *option_name); /* open a file with O_CLOEXEC */ diff --git a/src/lxc/tools/lxc_unshare.c b/src/lxc/tools/lxc_unshare.c index 59b8461a9..9c38f537f 100644 --- a/src/lxc/tools/lxc_unshare.c +++ b/src/lxc/tools/lxc_unshare.c @@ -104,6 +104,37 @@ struct start_arg { const char *want_hostname; }; +static int mount_fs(const char *source, const char *target, const char *type) +{ + /* the umount may fail */ + if (umount(target) < 0) + + if (mount(source, target, type, 0, NULL) < 0) + return -1; + + return 0; +} + +static void lxc_setup_fs(void) +{ + (void)mount_fs("proc", "/proc", "proc"); + + /* if /dev has been populated by us, /dev/shm does not exist */ + if (access("/dev/shm", F_OK)) + (void)mkdir("/dev/shm", 0777); + + /* if we can't mount /dev/shm, continue anyway */ + (void)mount_fs("shmfs", "/dev/shm", "tmpfs"); + + /* If we were able to mount /dev/shm, then /dev exists */ + /* Sure, but it's read-only per config :) */ + if (access("/dev/mqueue", F_OK)) + (void)mkdir("/dev/mqueue", 0666); + + /* continue even without posix message queue support */ + (void)mount_fs("mqueue", "/dev/mqueue", "mqueue"); +} + static int do_start(void *arg) { int ret;