Commit 6e4bb2e0 by Michel Normand Committed by Daniel Lezcano

lxc: move setup_fs to utils.c

This is not required immidiately but may be used by other init. Signed-off-by: 's avatarMichel Normand <normand@fr.ibm.com> Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent 96c210bb
......@@ -30,7 +30,6 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/mount.h>
#define _GNU_SOURCE
#include <getopt.h>
......@@ -52,42 +51,6 @@ static struct option options[] = {
{ 0, 0, 0, 0 },
};
static int mount_fs(const char *source, const char *target, const char *type)
{
/* the umount may fail */
if (umount(target))
WARN("failed to unmount %s : %s", target, strerror(errno));
if (mount(source, target, type, 0, NULL)) {
ERROR("failed to mount %s : %s", target, strerror(errno));
return -1;
}
DEBUG("'%s' mounted on '%s'", source, target);
return 0;
}
static inline int setup_fs(void)
{
if (mount_fs("proc", "/proc", "proc"))
return -1;
if (mount_fs("shmfs", "/dev/shm", "tmpfs"))
return -1;
/* If we were able to mount /dev/shm, then /dev exists */
if (access("/dev/mqueue", F_OK) && mkdir("/dev/mqueue", 0666)) {
SYSERROR("failed to create '/dev/mqueue'");
return -1;
}
if (mount_fs("mqueue", "/dev/mqueue", "mqueue"))
return -1;
return 0;
}
int main(int argc, char *argv[])
{
pid_t pid;
......@@ -127,7 +90,7 @@ int main(int argc, char *argv[])
if (!pid) {
if (setup_fs())
if (lxc_setup_fs())
exit(err);
NOTICE("about to exec '%s'", aargv[0]);
......@@ -171,3 +134,4 @@ int main(int argc, char *argv[])
out:
return err;
}
......@@ -30,6 +30,7 @@
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/param.h>
#include <sys/mount.h>
#include <dirent.h>
#include <fcntl.h>
......@@ -233,3 +234,39 @@ again:
return 0;
}
static int mount_fs(const char *source, const char *target, const char *type)
{
/* the umount may fail */
if (umount(target))
WARN("failed to unmount %s : %s", target, strerror(errno));
if (mount(source, target, type, 0, NULL)) {
ERROR("failed to mount %s : %s", target, strerror(errno));
return -1;
}
DEBUG("'%s' mounted on '%s'", source, target);
return 0;
}
extern int lxc_setup_fs(void)
{
if (mount_fs("proc", "/proc", "proc"))
return -1;
if (mount_fs("shmfs", "/dev/shm", "tmpfs"))
return -1;
/* If we were able to mount /dev/shm, then /dev exists */
if (access("/dev/mqueue", F_OK) && mkdir("/dev/mqueue", 0666)) {
SYSERROR("failed to create '/dev/mqueue'");
return -1;
}
if (mount_fs("mqueue", "/dev/mqueue", "mqueue"))
return -1;
return 0;
}
......@@ -53,3 +53,4 @@
extern int lxc_copy_file(const char *src, const char *dst);
extern int lxc_close_inherited_fd(int fd);
extern int lxc_close_all_inherited_fd(void);
extern int lxc_setup_fs(void);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment