]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
keep rcfile for lxc-execute as already done for lxc-create
authorMichel Normand <normand@fr.ibm.com>
Wed, 7 Oct 2009 08:05:39 +0000 (10:05 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Wed, 7 Oct 2009 08:05:39 +0000 (10:05 +0200)
The code previously added in lxc-create with
commit d7efa8fcbf0911f93c83dc06a708e7d73833dce3
is also required in lxc-execute.
So make this code common for the two callers.

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
src/lxc/conf.c
src/lxc/conf.h
src/lxc/confile.c
src/lxc/create.c
src/lxc/destroy.c
src/lxc/lxc_create.c
src/lxc/lxc_destroy.c

index 83ea2c33110dd6024f4e7d42527dc0b4df5782b1..78b2e24f2910cb6e65dd49ee0914e9a517891649 100644 (file)
@@ -1393,6 +1393,7 @@ out:
 
 int lxc_conf_init(struct lxc_conf *conf)
 {
+       conf->rcfile = NULL;
        conf->rootfs = NULL;
        conf->fstab = NULL;
        conf->utsname = NULL;
index 1f555880ad214c859de26e3785f29298b4327af4..9635ec9145a4f254153eed43141bf5c3110c8d00 100644 (file)
@@ -117,6 +117,7 @@ struct lxc_cgroup {
  * @utsname : the container utsname
  */
 struct lxc_conf {
+       const char *rcfile;
        char *rootfs;
        char *fstab;
        int tty;
index a1896c9a76af9c3987c5c09596386b8beda04d42..72f8103f80b174cd43f1c0b69abba1867f74eea3 100644 (file)
@@ -564,6 +564,8 @@ int lxc_config_read(const char *file, struct lxc_conf *conf)
 {
        char buffer[MAXPATHLEN];
 
+       conf->rcfile = file;
+
        return lxc_file_for_each_line(file, parse_line, buffer,
                                      sizeof(buffer), conf);
 }
index 64746b362cf5145610473ea09582a6d8c77fcd13..41ba5734ab494647361dcf625524fc4ea683b6c4 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
+#define _GNU_SOURCE
 #include <stdio.h>
+#undef _GNU_SOURCE
+#include <stdlib.h>
 #include <string.h>
 #include <dirent.h>
 #include <unistd.h>
@@ -95,6 +98,24 @@ static int remove_lxc_directory(const char *dirname)
        return 0;
 }
 
+static int copy_config_file(const char *name, const char *file)
+{
+       char *dst;
+       int ret;
+
+       if (!asprintf(&dst, LXCPATH "/%s/config", name)) {
+               ERROR("failed to allocate memory");
+               return -1;
+       }
+
+       ret = lxc_copy_file(file, dst);
+       if (ret)
+               ERROR("failed to copy '%s' to '%s'", file, dst);
+       free(dst);
+
+       return ret;
+}
+
 int lxc_create(const char *name, struct lxc_conf *conf)
 {
        int lock, err = -1;
@@ -121,6 +142,11 @@ int lxc_create(const char *name, struct lxc_conf *conf)
                goto err_state;
        }
 
+       if (conf->rcfile && copy_config_file(name, conf->rcfile)) {
+               ERROR("failed to copy the configuration file");
+               goto err_state;
+       }
+
        err = 0;
 out:
        lxc_put_lock(lock);
index a06d23b9e631fdc0b5f8b6b4caee8ab116296da0..63d7c3a1237bf13fe1b8e5f5d6938b6b92d27e2a 100644 (file)
@@ -49,6 +49,24 @@ static int remove_lxc_directory(const char *dirname)
        return 0;
 }
 
+static int remove_config_file(const char *name)
+{
+       char path[MAXPATHLEN];
+
+       snprintf(path, MAXPATHLEN, LXCPATH "/%s/config", name);
+
+       /* config file does not exists */
+       if (access(path, F_OK))
+               return 0;
+
+       if (unlink(path)) {
+               ERROR("failed to unlink '%s'", path);
+               return -1;
+       }
+
+       return 0;
+}
+
 int lxc_destroy(const char *name)
 {
        int lock, ret = -1;
@@ -58,6 +76,9 @@ int lxc_destroy(const char *name)
        if (lock < 0)
                return ret;
 
+       if (remove_config_file(name))
+               WARN("failed to remove the configuration file");
+
        if (lxc_rmstate(name)) {
                ERROR("failed to remove state file for %s", name);
                goto out_lock;
index 110d682747eacf093bef2b1bd00efab0c1df42b1..f0167988088e25774f429606e28afc806f837b67 100644 (file)
@@ -67,24 +67,6 @@ Options :\n\
        .checker  = NULL,
 };
 
-static int copy_config_file(const char *name, const char *file)
-{
-       char *src;
-       int ret;
-
-       if (!asprintf(&src, LXCPATH "/%s/config", name)) {
-               ERROR("failed to allocate memory");
-               return -1;
-       }
-
-       ret = lxc_copy_file(file, src);
-       if (ret)
-               ERROR("failed to copy '%s' to '%s'", file, src);
-       free(src);
-
-       return ret;
-}
-
 int main(int argc, char *argv[])
 {
        struct lxc_conf lxc_conf;
@@ -111,12 +93,6 @@ int main(int argc, char *argv[])
                return -1;
        }
 
-       if (my_args.rcfile && copy_config_file(my_args.name, my_args.rcfile)) {
-               ERROR("failed to copy the configuration file");
-               lxc_destroy(my_args.name);
-               return -1;
-       }
-
        INFO("'%s' created", my_args.name);
 
        return 0;
index 7aef61687af63b4cf1ba1f6c859d8ff7c6fcac09..89b7e34fbd197da88ea65f3386f6490d0bc6fb82 100644 (file)
@@ -48,24 +48,6 @@ Options :\n\
        .checker  = NULL,
 };
 
-static int remove_config_file(const char *name)
-{
-       char path[MAXPATHLEN];
-
-       snprintf(path, MAXPATHLEN, LXCPATH "/%s/config", name);
-
-       /* config file does not exists */
-       if (access(path, F_OK))
-               return 0;
-
-       if (unlink(path)) {
-               ERROR("failed to unlink '%s'", path);
-               return -1;
-       }
-
-       return 0;
-}
-
 int main(int argc, char *argv[])
 {
        if (lxc_arguments_parse(&my_args, argc, argv))
@@ -75,9 +57,6 @@ int main(int argc, char *argv[])
                         my_args.progname, my_args.quiet))
                return -1;
 
-       if (remove_config_file(my_args.name))
-               WARN("failed to remove the configuration file");
-
        if (lxc_destroy(my_args.name)) {
                ERROR("failed to destroy the container");
                return -1;