aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Lezcano <daniel.lezcano@free.fr>2009-11-17 22:57:46 +0100
committerDaniel Lezcano <dlezcano@fr.ibm.com>2009-11-17 22:57:46 +0100
commit96c210bbbe1a6c0b06aa38ad1662620ac57bbe4a (patch)
treef6af1788f8999ef0db9ac6169998382d9135e924
parentlxc-netstat should use @LXCPATH@ for lxcpath= (diff)
downloadlxc-96c210bbbe1a6c0b06aa38ad1662620ac57bbe4a.tar.gz
lxc-96c210bbbe1a6c0b06aa38ad1662620ac57bbe4a.tar.bz2
lxc-96c210bbbe1a6c0b06aa38ad1662620ac57bbe4a.zip
fix container find the previously created configuration
The command specifies a configuration file => use it The command does not specify a configuration but the container was created before, use the configuration. The command does not specify a configuration and the container was not created before, use default. Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
-rw-r--r--src/lxc/lxc_execute.c17
-rw-r--r--src/lxc/lxc_start.c24
2 files changed, 40 insertions, 1 deletions
diff --git a/src/lxc/lxc_execute.c b/src/lxc/lxc_execute.c
index 5821350..efc03eb 100644
--- a/src/lxc/lxc_execute.c
+++ b/src/lxc/lxc_execute.c
@@ -82,6 +82,7 @@ Options :\n\
int main(int argc, char *argv[])
{
static char **args;
+ char *rcfile;
if (lxc_arguments_parse(&my_args, argc, argv))
return -1;
@@ -94,6 +95,22 @@ int main(int argc, char *argv[])
if (!args)
return -1;
+ /* rcfile is specified in the cli option */
+ if (my_args.rcfile)
+ rcfile = (char *)my_args.rcfile;
+ else {
+ if (!asprintf(&rcfile, LXCPATH "/%s", my_args.name)) {
+ SYSERROR("failed to allocate memory");
+ return -1;
+ }
+
+ /* container configuration does not exist */
+ if (access(rcfile, F_OK)) {
+ free(rcfile);
+ rcfile = NULL;
+ }
+ }
+
return lxc_start(my_args.name, args, my_args.rcfile);
}
diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c
index de78290..9e14b8f 100644
--- a/src/lxc/lxc_start.c
+++ b/src/lxc/lxc_start.c
@@ -20,8 +20,11 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#define _GNU_SOURCE
#include <stdio.h>
+#undef _GNU_SOURCE
#include <libgen.h>
+#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <termios.h>
@@ -42,6 +45,7 @@
#include <lxc/utils.h>
#include "arguments.h"
+#include "config.h"
lxc_log_define(lxc_start, lxc);
@@ -127,6 +131,8 @@ int main(int argc, char *argv[])
'\0',
};
+ char *rcfile = NULL;
+
if (lxc_arguments_parse(&my_args, argc, argv))
return err;
@@ -139,6 +145,22 @@ int main(int argc, char *argv[])
my_args.progname, my_args.quiet))
return err;
+ /* rcfile is specified in the cli option */
+ if (my_args.rcfile)
+ rcfile = (char *)my_args.rcfile;
+ else {
+ if (!asprintf(&rcfile, LXCPATH "/%s", my_args.name)) {
+ SYSERROR("failed to allocate memory");
+ return err;
+ }
+
+ /* container configuration does not exist */
+ if (access(rcfile, F_OK)) {
+ free(rcfile);
+ rcfile = NULL;
+ }
+ }
+
if (my_args.daemonize) {
/* do not chdir as we want to open the log file,
@@ -167,7 +189,7 @@ int main(int argc, char *argv[])
save_tty(&tios);
- err = lxc_start(my_args.name, args, my_args.rcfile);
+ err = lxc_start(my_args.name, args, rcfile);
restore_tty(&tios);