Commit 20117280 by Cedric Le Goater Committed by Daniel Lezcano

add --define to execute

parent 62e46035
...@@ -49,7 +49,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ...@@ -49,7 +49,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
<refsynopsisdiv> <refsynopsisdiv>
<cmdsynopsis> <cmdsynopsis>
<command>lxc-execute <replaceable>-n name</replaceable> <command>lxc-execute <replaceable>-n name</replaceable>
<optional>-f config_file</optional> <optional>-f config_file</optional> <optional>-s KEY=VAL
</optional>
<replaceable>command</replaceable> <replaceable>command</replaceable>
</command> </command>
</cmdsynopsis> </cmdsynopsis>
...@@ -90,6 +91,18 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ...@@ -90,6 +91,18 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>
<option>-s <replaceable>KEY=VAL</replaceable></option>
</term>
<listitem>
<para>
Assign value <replaceable>VAL</replaceable> to configuration
variable <replaceable>KEY</replaceable>. This overrides any
assignment done in <replaceable>config_file</replaceable>.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
......
...@@ -41,6 +41,8 @@ ...@@ -41,6 +41,8 @@
lxc_log_define(lxc_execute_ui, lxc_start); lxc_log_define(lxc_execute_ui, lxc_start);
static struct lxc_list defines;
static int my_checker(const struct lxc_arguments* args) static int my_checker(const struct lxc_arguments* args)
{ {
if (!args->argc) { if (!args->argc) {
...@@ -55,12 +57,14 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg) ...@@ -55,12 +57,14 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
{ {
switch (c) { switch (c) {
case 'f': args->rcfile = arg; break; case 'f': args->rcfile = arg; break;
case 's': return lxc_config_define_add(&defines, arg);
} }
return 0; return 0;
} }
static const struct option my_longopts[] = { static const struct option my_longopts[] = {
{"rcfile", required_argument, 0, 'f'}, {"rcfile", required_argument, 0, 'f'},
{"define", required_argument, 0, 's'},
LXC_COMMON_OPTIONS LXC_COMMON_OPTIONS
}; };
...@@ -73,8 +77,9 @@ lxc-execute creates a container with the identifier NAME\n\ ...@@ -73,8 +77,9 @@ lxc-execute creates a container with the identifier NAME\n\
and execs COMMAND into this container.\n\ and execs COMMAND into this container.\n\
\n\ \n\
Options :\n\ Options :\n\
-n, --name=NAME NAME for name of the container\n\ -n, --name=NAME NAME for name of the container\n\
-f, --rcfile=FILE Load configuration file FILE\n", -f, --rcfile=FILE Load configuration file FILE\n\
-s, --define KEY=VAL Assign VAL to configuration variable KEY\n",
.options = my_longopts, .options = my_longopts,
.parser = my_parser, .parser = my_parser,
.checker = my_checker, .checker = my_checker,
...@@ -86,6 +91,8 @@ int main(int argc, char *argv[]) ...@@ -86,6 +91,8 @@ int main(int argc, char *argv[])
char *rcfile; char *rcfile;
struct lxc_conf *conf; struct lxc_conf *conf;
lxc_list_init(&defines);
if (lxc_arguments_parse(&my_args, argc, argv)) if (lxc_arguments_parse(&my_args, argc, argv))
return -1; return -1;
...@@ -124,6 +131,9 @@ int main(int argc, char *argv[]) ...@@ -124,6 +131,9 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
if (lxc_config_define_load(&defines, conf))
return -1;
return lxc_start(my_args.name, args, conf); return lxc_start(my_args.name, args, conf);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment