]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
add --define to restart
authorCedric Le Goater <clg@fr.ibm.com>
Thu, 14 Jan 2010 06:43:18 +0000 (07:43 +0100)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Thu, 14 Jan 2010 06:43:18 +0000 (07:43 +0100)
Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
src/lxc/lxc_restart.c

index 9cad3177a987ec8c9295b50d652a323fdae60edc..cfadd05be6a98ff8c566631307a755db2763f40f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * lxc: linux Container library
  *
- * (C) Copyright IBM Corp. 2007, 2008
+ * (C) Copyright IBM Corp. 2007, 2010
  *
  * Authors:
  * Daniel Lezcano <dlezcano at fr.ibm.com>
 #undef _GNU_SOURCE
 #include <stdlib.h>
 #include <unistd.h>
+#include <errno.h>
 #include <sys/types.h>
 
-#include <lxc/lxc.h>
-#include <lxc/log.h>
-
+#include "log.h"
+#include "lxc.h"
+#include "conf.h"
+#include "config.h"
+#include "confile.h"
 #include "arguments.h"
 
 lxc_log_define(lxc_restart_ui, lxc_restart);
@@ -81,6 +84,9 @@ Options :\n\
 
 int main(int argc, char *argv[])
 {
+       char *rcfile = NULL;
+       struct lxc_conf *conf;
+
        if (lxc_arguments_parse(&my_args, argc, argv))
                return -1;
 
@@ -88,6 +94,33 @@ int main(int argc, char *argv[])
                         my_args.progname, my_args.quiet))
                return -1;
 
-       return lxc_restart(my_args.name, my_args.statefile, my_args.rcfile,
+       /* rcfile is specified in the cli option */
+       if (my_args.rcfile)
+               rcfile = (char *)my_args.rcfile;
+       else {
+               if (!asprintf(&rcfile, LXCPATH "/%s/config", my_args.name)) {
+                       SYSERROR("failed to allocate memory");
+                       return -1;
+               }
+
+               /* container configuration does not exist */
+               if (access(rcfile, F_OK)) {
+                       free(rcfile);
+                       rcfile = NULL;
+               }
+       }
+
+       conf = lxc_conf_init();
+       if (!conf) {
+               ERROR("failed to initialize configuration");
+               return -1;
+       }
+
+       if (rcfile && lxc_config_read(rcfile, conf)) {
+               ERROR("failed to read configuration file");
+               return -1;
+       }
+
+       return lxc_restart(my_args.name, my_args.statefile, conf,
                           my_args.flags);
 }