From: Michel Normand Date: Tue, 17 Nov 2009 21:57:46 +0000 (+0100) Subject: lxc: move setup_fs to utils.c X-Git-Tag: lxc_0_6_4~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e4bb2e01f407fbecc7fc82496ac96065352a053;p=thirdparty%2Flxc.git lxc: move setup_fs to utils.c This is not required immidiately but may be used by other init. Signed-off-by: Michel Normand Signed-off-by: Daniel Lezcano --- diff --git a/src/lxc/lxc_init.c b/src/lxc/lxc_init.c index 191f7c4da..0230d75fb 100644 --- a/src/lxc/lxc_init.c +++ b/src/lxc/lxc_init.c @@ -30,7 +30,6 @@ #include #include #include -#include #define _GNU_SOURCE #include @@ -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; } + diff --git a/src/lxc/utils.c b/src/lxc/utils.c index 492c885f2..f9477a347 100644 --- a/src/lxc/utils.c +++ b/src/lxc/utils.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -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; +} diff --git a/src/lxc/utils.h b/src/lxc/utils.h index c0c47d005..cb4e6a0bb 100644 --- a/src/lxc/utils.h +++ b/src/lxc/utils.h @@ -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);