]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Move the configuration file to the start function
authorDaniel Lezcano <dlezcano@fr.ibm.com>
Fri, 9 Oct 2009 09:38:39 +0000 (11:38 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Fri, 9 Oct 2009 09:38:39 +0000 (11:38 +0200)
We want to store more information in the configuration structure,
especially the ttys.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
src/lxc/conf.c
src/lxc/conf.h
src/lxc/start.c
src/lxc/start.h

index 347757110462b973512d2585c207406cc608c3b8..b783b1b040962e6e4831dd196fb6c6b1e379fe09 100644 (file)
@@ -1619,66 +1619,44 @@ void lxc_delete_tty(struct lxc_tty_info *tty_info)
        tty_info->nbtty = 0;
 }
 
-extern int lxc_config_read(const char *file, struct lxc_conf *conf);
-
-int lxc_setup(const char *name, const char *cons,
-             const struct lxc_tty_info *tty_info)
-
+int lxc_setup(const char *name, struct lxc_handler *handler)
 {
-       struct lxc_conf lxc_conf;
-       char path[MAXPATHLEN];
-
-       if (lxc_conf_init(&lxc_conf)) {
-               ERROR("failed to initialize the configuration");
-               return -1;
-       }
-
-       snprintf(path, sizeof(path), LXCPATH "/%s/config", name);
-
-       if (!access(path, F_OK)) {
-
-               if (lxc_config_read(path, &lxc_conf)) {
-                       ERROR("failed to read the configuration file");
-                       return -1;
-               }
-       }
-
-       if (setup_utsname(lxc_conf.utsname)) {
+       if (setup_utsname(handler->lxc_conf.utsname)) {
                ERROR("failed to setup the utsname for '%s'", name);
                return -1;
        }
 
-       if (!lxc_list_empty(&lxc_conf.networks) && setup_network(name)) {
+       if (!lxc_list_empty(&handler->lxc_conf.networks) && setup_network(name)) {
                ERROR("failed to setup the network for '%s'", name);
                return -1;
        }
 
-       if (setup_cgroup(name, &lxc_conf.cgroup)) {
+       if (setup_cgroup(name, &handler->lxc_conf.cgroup)) {
                ERROR("failed to setup the cgroups for '%s'", name);
                return -1;
        }
 
-       if (setup_mount(lxc_conf.fstab)) {
+       if (setup_mount(handler->lxc_conf.fstab)) {
                ERROR("failed to setup the mounts for '%s'", name);
                return -1;
        }
 
-       if (setup_console(lxc_conf.rootfs, cons)) {
+       if (setup_console(handler->lxc_conf.rootfs, handler->tty)) {
                ERROR("failed to setup the console for '%s'", name);
                return -1;
        }
 
-       if (setup_tty(lxc_conf.rootfs, tty_info)) {
+       if (setup_tty(handler->lxc_conf.rootfs, &handler->tty_info)) {
                ERROR("failed to setup the ttys for '%s'", name);
                return -1;
        }
 
-       if (setup_rootfs(lxc_conf.rootfs)) {
+       if (setup_rootfs(handler->lxc_conf.rootfs)) {
                ERROR("failed to set rootfs for '%s'", name);
                return -1;
        }
 
-       if (setup_pts(lxc_conf.pts)) {
+       if (setup_pts(handler->lxc_conf.pts)) {
                ERROR("failed to setup the new pts instance");
                return -1;
        }
index 9635ec9145a4f254153eed43141bf5c3110c8d00..17a69c8b6874a5f435e4fbf074d12adce57c3f70 100644 (file)
@@ -176,8 +176,10 @@ extern void lxc_delete_tty(struct lxc_tty_info *tty_info);
 /*
  * Configure the container from inside
  */
-extern int lxc_setup(const char *name, const char *tty,
-                    const struct lxc_tty_info *tty_info);
+
+struct lxc_handler;
+
+extern int lxc_setup(const char *name, struct lxc_handler *handler);
 
 extern int conf_has(const char *name, const char *info);
 
index 2447b2d5fd3ec4a602ca7090bde2ca3e1d18175b..8fb8e368875e015c8b0d322a62f75da61e49e428 100644 (file)
@@ -44,6 +44,9 @@
 #include <sys/un.h>
 #include <sys/poll.h>
 
+#include <lxc/lxc.h>
+#include <lxc/confile.h>
+
 #ifdef HAVE_SYS_SIGNALFD_H 
 #  include <sys/signalfd.h>
 #else
@@ -235,6 +238,7 @@ static int console_init(char *console, size_t size)
 struct lxc_handler *lxc_init(const char *name)
 {
        struct lxc_handler *handler;
+       char path[MAXPATHLEN];
 
        handler = malloc(sizeof(*handler));
        if (!handler)
@@ -252,6 +256,21 @@ struct lxc_handler *lxc_init(const char *name)
                goto out_put_lock;
        }
 
+       if (lxc_conf_init(&handler->lxc_conf)) {
+               ERROR("failed to initialize the configuration");
+               goto out_aborting;
+       }
+
+       snprintf(path, sizeof(path), LXCPATH "/%s/config", name);
+
+       if (!access(path, F_OK)) {
+
+               if (lxc_config_read(path, &handler->lxc_conf)) {
+                       ERROR("failed to read the configuration file");
+                       goto out_aborting;
+               }
+       }
+
        if (console_init(handler->tty, sizeof(handler->tty))) {
                ERROR("failed to initialize the console");
                goto out_aborting;
@@ -358,7 +377,7 @@ static int do_start(void *arg)
        }
 
        /* Setup the container, ip, names, utsname, ... */
-       if (lxc_setup(name, handler->tty, &handler->tty_info)) {
+       if (lxc_setup(name, handler)) {
                ERROR("failed to setup the container");
                goto out_warn_father;
        }
index bb86f404aaf91ab42b4207425deea8d0dc666f55..e838754b06a032f6ffb70205f933c92b953cb4bd 100644 (file)
@@ -32,6 +32,7 @@ struct lxc_handler {
        char nsgroup[MAXPATHLEN];
        sigset_t oldmask;
        struct lxc_tty_info tty_info;
+       struct lxc_conf lxc_conf;
 };
 
 extern struct lxc_handler *lxc_init(const char *name);