Commit fe3b02ff by Wolfgang Bumiller Committed by Stéphane Graber

tools: move --rcfile to the common options list

In almost all commands it's a useful addition to the -n switch which is a common option, too. Signed-off-by: 's avatarWolfgang Bumiller <w.bumiller@proxmox.com>
parent 3b9494bd
......@@ -203,6 +203,7 @@ extern int lxc_arguments_parse(struct lxc_arguments *args,
case 'o': args->log_file = optarg; break;
case 'l': args->log_priority = optarg; break;
case 'q': args->quiet = 1; break;
case OPT_RCFILE: args->rcfile = optarg; break;
case 'P':
remove_trailing_slashes(optarg);
ret = lxc_arguments_lxcpath_add(args, optarg);
......
......@@ -148,11 +148,13 @@ struct lxc_arguments {
{"logfile", required_argument, 0, 'o'}, \
{"logpriority", required_argument, 0, 'l'}, \
{"lxcpath", required_argument, 0, 'P'}, \
{"rcfile", required_argument, 0, OPT_RCFILE}, \
{0, 0, 0, 0}
/* option keys for long only options */
#define OPT_USAGE 0x1000
#define OPT_VERSION OPT_USAGE-1
#define OPT_RCFILE OPT_USAGE-2
extern int lxc_arguments_parse(struct lxc_arguments *args,
int argc, char *const argv[]);
......
......@@ -56,7 +56,8 @@ Get or set the value of a state object (for example, 'cpuset.cpus')\n\
in the container's cgroup for the corresponding subsystem.\n\
\n\
Options :\n\
-n, --name=NAME NAME of the container",
-n, --name=NAME NAME of the container\n\
--rcfile=FILE Load configuration file FILE\n",
.options = my_longopts,
.parser = NULL,
.checker = my_checker,
......@@ -84,6 +85,15 @@ int main(int argc, char *argv[])
if (!c)
return 1;
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);
return 1;
}
}
if (!c->may_control(c)) {
ERROR("Insufficent privileges to control %s:%s", my_args.lxcpath[0], my_args.name);
lxc_container_put(c);
......
......@@ -114,6 +114,7 @@ Options :\n\
Restore options:\n\
-d, --daemon Daemonize the container (default)\n\
-F, --foreground Start with the current tty attached to /dev/console\n\
--rcfile=FILE Load configuration file FILE\n\
",
.options = my_longopts,
.parser = my_parser,
......@@ -214,6 +215,15 @@ int main(int argc, char *argv[])
exit(1);
}
if (my_args.rcfile) {
c->clear_config(c);
if (!c->load_config(c, my_args.rcfile)) {
fprintf(stderr, "Failed to load rcfile\n");
lxc_container_put(c);
exit(1);
}
}
if (!c->may_control(c)) {
fprintf(stderr, "Insufficent privileges to control %s\n", my_args.name);
lxc_container_put(c);
......
......@@ -80,7 +80,8 @@ lxc-console logs on the container with the identifier NAME\n\
Options :\n\
-n, --name=NAME NAME of the container\n\
-t, --tty=NUMBER console tty number\n\
-e, --escape=PREFIX prefix for escape command\n",
-e, --escape=PREFIX prefix for escape command\n\
--rcfile=FILE Load configuration file FILE\n",
.options = my_longopts,
.parser = my_parser,
.checker = NULL,
......@@ -112,6 +113,15 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
if (my_args.rcfile) {
c->clear_config(c);
if (!c->load_config(c, my_args.rcfile)) {
fprintf(stderr, "Failed to load rcfile\n");
lxc_container_put(c);
exit(EXIT_FAILURE);
}
}
if (!c->may_control(c)) {
fprintf(stderr, "Insufficent privileges to control %s\n", my_args.name);
lxc_container_put(c);
......
......@@ -123,7 +123,8 @@ Options :\n\
-D, --keedata pass together with -e start a persistent snapshot \n\
-K, --keepname keep the hostname of the original container\n\
-- hook options arguments passed to the hook program\n\
-M, --keepmac keep the MAC address of the original container\n",
-M, --keepmac keep the MAC address of the original container\n\
--rcfile=FILE Load configuration file FILE\n",
.options = my_longopts,
.parser = my_parser,
.task = CLONE,
......@@ -199,6 +200,14 @@ int main(int argc, char *argv[])
if (!c)
exit(ret);
if (my_args.rcfile) {
c->clear_config(c);
if (!c->load_config(c, my_args.rcfile)) {
fprintf(stderr, "Failed to load rcfile\n");
goto out;
}
}
if (!c->may_control(c)) {
if (!my_args.quiet)
fprintf(stderr, "Insufficent privileges to control %s\n", c->name);
......
......@@ -53,7 +53,8 @@ lxc-destroy destroys a container with the identifier NAME\n\
Options :\n\
-n, --name=NAME NAME of the container\n\
-s, --snapshots destroy including all snapshots\n\
-f, --force wait for the container to shut down\n",
-f, --force wait for the container to shut down\n\
--rcfile=FILE Load configuration file FILE\n",
.options = my_longopts,
.parser = my_parser,
.checker = NULL,
......@@ -88,6 +89,15 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
if (my_args.rcfile) {
c->clear_config(c);
if (!c->load_config(c, my_args.rcfile)) {
fprintf(stderr, "Failed to load rcfile\n");
lxc_container_put(c);
exit(EXIT_FAILURE);
}
}
if (!c->may_control(c)) {
if (!quiet)
fprintf(stderr, "Insufficent privileges to control %s\n", my_args.name);
......
......@@ -53,7 +53,8 @@ static struct lxc_arguments my_args = {
lxc-device attach or detach DEV to or from container.\n\
\n\
Options :\n\
-n, --name=NAME NAME of the container",
-n, --name=NAME NAME of the container\n\
--rcfile=FILE Load configuration file FILE\n",
.options = my_longopts,
.parser = NULL,
.checker = NULL,
......@@ -125,6 +126,14 @@ int main(int argc, char *argv[])
goto err;
}
if (my_args.rcfile) {
c->clear_config(c);
if (!c->load_config(c, my_args.rcfile)) {
ERROR("Failed to load rcfile");
goto err1;
}
}
if (!c->is_running(c)) {
ERROR("Container %s is not running.", c->name);
goto err1;
......
......@@ -47,7 +47,8 @@ static struct lxc_arguments my_args = {
lxc-freeze freezes a container with the identifier NAME\n\
\n\
Options :\n\
-n, --name=NAME NAME of the container",
-n, --name=NAME NAME of the container\n\
--rcfile=FILE Load configuration file FILE\n",
.options = my_longopts,
.parser = NULL,
.checker = NULL,
......@@ -74,6 +75,15 @@ int main(int argc, char *argv[])
exit(1);
}
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(1);
}
}
if (!c->may_control(c)) {
ERROR("Insufficent privileges to control %s:%s", my_args.lxcpath[0], my_args.name);
lxc_container_put(c);
......
......@@ -93,7 +93,8 @@ Options :\n\
-p, --pid shows the process id of the init container\n\
-S, --stats shows usage stats\n\
-H, --no-humanize shows stats as raw numbers, not humanized\n\
-s, --state shows the state of the container\n",
-s, --state shows the state of the container\n\
--rcfile=FILE Load configuration file FILE\n",
.name = NULL,
.options = my_longopts,
.parser = my_parser,
......@@ -295,6 +296,15 @@ static int print_info(const char *name, const char *lxcpath)
return -1;
}
if (my_args.rcfile) {
c->clear_config(c);
if (!c->load_config(c, my_args.rcfile)) {
fprintf(stderr, "Failed to load rcfile\n");
lxc_container_put(c);
return -1;
}
}
if (!c->may_control(c)) {
fprintf(stderr, "Insufficent privileges to control %s\n", c->name);
lxc_container_put(c);
......
......@@ -62,7 +62,8 @@ Options :\n\
-d, --destroy=NAME destroy snapshot NAME, e.g. 'snap0'\n\
use ALL to destroy all snapshots\n\
-c, --comment=FILE add FILE as a comment\n\
-C, --showcomments show snapshot comments\n",
-C, --showcomments show snapshot comments\n\
--rcfile=FILE Load configuration file FILE\n",
.options = my_longopts,
.parser = my_parser,
.checker = NULL,
......@@ -107,6 +108,15 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
if (my_args.rcfile) {
c->clear_config(c);
if (!c->load_config(c, my_args.rcfile)) {
fprintf(stderr, "Failed to load rcfile\n");
lxc_container_put(c);
exit(EXIT_FAILURE);
}
}
if (!c->may_control(c)) {
fprintf(stderr, "Insufficent privileges to control %s\n",
my_args.name);
......
......@@ -75,7 +75,8 @@ Options :\n\
-t, --timeout=T wait T seconds before hard-stopping\n\
-k, --kill kill container rather than request clean shutdown\n\
--nolock Avoid using API locks\n\
--nokill Only request clean shutdown, don't force kill after timeout\n",
--nokill Only request clean shutdown, don't force kill after timeout\n\
--rcfile=FILE Load configuration file FILE\n",
.options = my_longopts,
.parser = my_parser,
.checker = NULL,
......@@ -203,6 +204,14 @@ int main(int argc, char *argv[])
goto out;
}
if (my_args.rcfile) {
c->clear_config(c);
if (!c->load_config(c, my_args.rcfile)) {
fprintf(stderr, "Failed to load rcfile\n");
goto out;
}
}
if (!c->may_control(c)) {
fprintf(stderr, "Insufficent privileges to control %s\n", c->name);
goto out;
......
......@@ -45,7 +45,8 @@ static struct lxc_arguments my_args = {
lxc-unfreeze unfreezes a container with the identifier NAME\n\
\n\
Options :\n\
-n, --name=NAME NAME of the container\n",
-n, --name=NAME NAME of the container\n\
--rcfile=FILE Load configuration file FILE\n",
.options = my_longopts,
.parser = NULL,
.checker = NULL,
......@@ -78,6 +79,15 @@ int main(int argc, char *argv[])
exit(1);
}
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(1);
}
}
if (!c->unfreeze(c)) {
ERROR("Failed to unfreeze %s:%s", my_args.lxcpath[0], my_args.name);
lxc_container_put(c);
......
......@@ -72,7 +72,8 @@ Options :\n\
-s, --state=STATE ORed states to wait for\n\
STOPPED, STARTING, RUNNING, STOPPING,\n\
ABORTING, FREEZING, FROZEN, THAWED\n\
-t, --timeout=TMO Seconds to wait for state changes\n",
-t, --timeout=TMO Seconds to wait for state changes\n\
--rcfile=FILE Load configuration file FILE\n",
.options = my_longopts,
.parser = my_parser,
.checker = my_checker,
......@@ -104,6 +105,15 @@ int main(int argc, char *argv[])
return 1;
}
if (my_args.rcfile) {
c->clear_config(c);
if (!c->load_config(c, my_args.rcfile)) {
fprintf(stderr, "Failed to load rcfile\n");
lxc_container_put(c);
return 1;
}
}
if (!c->wait(c, my_args.states, my_args.timeout)) {
lxc_container_put(c);
return 1;
......
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