Commit a7104b0b by Wolfgang Bumiller Committed by Stéphane Graber

add -f option to lxc-attach

Otherwise a container with a non-standard configuration file can be started but not attached to. Fixes the following case: # lxc-start -n ct -f /different/path/my.config # lxc-attach -n ct Error: container ct is not defined Signed-off-by: 's avatarWolfgang Bumiller <w.bumiller@proxmox.com>
parent 5a213360
...@@ -65,6 +65,7 @@ static const struct option my_longopts[] = { ...@@ -65,6 +65,7 @@ static const struct option my_longopts[] = {
{"keep-var", required_argument, 0, 502}, {"keep-var", required_argument, 0, 502},
{"set-var", required_argument, 0, 'v'}, {"set-var", required_argument, 0, 'v'},
{"pty-log", required_argument, 0, 'L'}, {"pty-log", required_argument, 0, 'L'},
{"rcfile", required_argument, 0, 'f'},
LXC_COMMON_OPTIONS LXC_COMMON_OPTIONS
}; };
...@@ -153,6 +154,7 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg) ...@@ -153,6 +154,7 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
case 'L': case 'L':
args->console_log = arg; args->console_log = arg;
break; break;
case 'f': args->rcfile = arg; break;
} }
return 0; return 0;
...@@ -202,7 +204,10 @@ Options :\n\ ...@@ -202,7 +204,10 @@ Options :\n\
multiple times.\n\ multiple times.\n\
--keep-var Keep an additional environment variable. Only\n\ --keep-var Keep an additional environment variable. Only\n\
applicable if --clear-env is specified. May be used\n\ applicable if --clear-env is specified. May be used\n\
multiple times.\n", multiple times.\n\
-f, --rcfile=FILE\n\
Load configuration file FILE\n\
",
.options = my_longopts, .options = my_longopts,
.parser = my_parser, .parser = my_parser,
.checker = NULL, .checker = NULL,
...@@ -373,6 +378,15 @@ int main(int argc, char *argv[]) ...@@ -373,6 +378,15 @@ int main(int argc, char *argv[])
if (!c) if (!c)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
if (my_args.rcfile) {
c->clear_config(c);
if (!c->load_config(c, my_args.rcfile)) {
ERROR("Failed to load rcfile");
lxc_container_put(c);
exit(EXIT_FAILURE);
}
}
if (!c->may_control(c)) { if (!c->may_control(c)) {
fprintf(stderr, "Insufficent privileges to control %s\n", c->name); fprintf(stderr, "Insufficent privileges to control %s\n", c->name);
lxc_container_put(c); lxc_container_put(c);
......
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