Unverified Commit bb19d0ab by 2xsec Committed by Christian Brauner

tools: lxc-execute: add default log priority & cleanups

Signed-off-by: 's avatar2xsec <dh48.jeong@samsung.com>
parent 3920d874
...@@ -43,8 +43,46 @@ ...@@ -43,8 +43,46 @@
lxc_log_define(lxc_execute, lxc); lxc_log_define(lxc_execute, lxc);
static int my_parser(struct lxc_arguments *args, int c, char *arg);
static bool set_argv(struct lxc_container *c, struct lxc_arguments *args);
static struct lxc_list defines; static struct lxc_list defines;
static const struct option my_longopts[] = {
{"daemon", no_argument, 0, 'd'},
{"rcfile", required_argument, 0, 'f'},
{"define", required_argument, 0, 's'},
{"uid", required_argument, 0, 'u'},
{"gid", required_argument, 0, 'g'},
{"share-net", required_argument, 0, OPT_SHARE_NET},
{"share-ipc", required_argument, 0, OPT_SHARE_IPC},
{"share-uts", required_argument, 0, OPT_SHARE_UTS},
{"share-pid", required_argument, 0, OPT_SHARE_PID},
LXC_COMMON_OPTIONS
};
static struct lxc_arguments my_args = {
.progname = "lxc-execute",
.help = "\
--name=NAME -- COMMAND\n\
\n\
lxc-execute creates a container with the identifier NAME\n\
and execs COMMAND into this container.\n\
\n\
Options :\n\
-n, --name=NAME NAME of the container\n\
-d, --daemon Daemonize the container\n\
-f, --rcfile=FILE Load configuration file FILE\n\
-s, --define KEY=VAL Assign VAL to configuration variable KEY\n\
-u, --uid=UID Execute COMMAND with UID inside the container\n\
-g, --gid=GID Execute COMMAND with GID inside the container\n",
.options = my_longopts,
.parser = my_parser,
.log_priority = "ERROR",
.log_file = "none",
.daemonize = 0,
};
static int my_parser(struct lxc_arguments *args, int c, char *arg) static int my_parser(struct lxc_arguments *args, int c, char *arg)
{ {
int ret; int ret;
...@@ -82,43 +120,9 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg) ...@@ -82,43 +120,9 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
args->share_ns[LXC_NS_PID] = arg; args->share_ns[LXC_NS_PID] = arg;
break; break;
} }
return 0; return 0;
} }
static const struct option my_longopts[] = {
{"daemon", no_argument, 0, 'd'},
{"rcfile", required_argument, 0, 'f'},
{"define", required_argument, 0, 's'},
{"uid", required_argument, 0, 'u'},
{"gid", required_argument, 0, 'g'},
{"share-net", required_argument, 0, OPT_SHARE_NET},
{"share-ipc", required_argument, 0, OPT_SHARE_IPC},
{"share-uts", required_argument, 0, OPT_SHARE_UTS},
{"share-pid", required_argument, 0, OPT_SHARE_PID},
LXC_COMMON_OPTIONS
};
static struct lxc_arguments my_args = {
.progname = "lxc-execute",
.help = "\
--name=NAME -- COMMAND\n\
\n\
lxc-execute creates a container with the identifier NAME\n\
and execs COMMAND into this container.\n\
\n\
Options :\n\
-n, --name=NAME NAME of the container\n\
-d, --daemon Daemonize the container\n\
-f, --rcfile=FILE Load configuration file FILE\n\
-s, --define KEY=VAL Assign VAL to configuration variable KEY\n\
-u, --uid=UID Execute COMMAND with UID inside the container\n\
-g, --gid=GID Execute COMMAND with GID inside the container\n",
.options = my_longopts,
.parser = my_parser,
.daemonize = 0,
};
static bool set_argv(struct lxc_container *c, struct lxc_arguments *args) static bool set_argv(struct lxc_container *c, struct lxc_arguments *args)
{ {
int ret; int ret;
...@@ -134,6 +138,7 @@ static bool set_argv(struct lxc_container *c, struct lxc_arguments *args) ...@@ -134,6 +138,7 @@ static bool set_argv(struct lxc_container *c, struct lxc_arguments *args)
return false; return false;
args->argv = components; args->argv = components;
for (p = components; *p; p++) for (p = components; *p; p++)
args->argc++; args->argc++;
...@@ -156,8 +161,6 @@ int main(int argc, char *argv[]) ...@@ -156,8 +161,6 @@ int main(int argc, char *argv[])
if (lxc_arguments_parse(&my_args, argc, argv)) if (lxc_arguments_parse(&my_args, argc, argv))
exit(err); exit(err);
/* Only create log if explicitly instructed */
if (my_args.log_file || my_args.log_priority) {
log.name = my_args.name; log.name = my_args.name;
log.file = my_args.log_file; log.file = my_args.log_file;
log.level = my_args.log_priority; log.level = my_args.log_priority;
...@@ -167,7 +170,6 @@ int main(int argc, char *argv[]) ...@@ -167,7 +170,6 @@ int main(int argc, char *argv[])
if (lxc_log_init(&log)) if (lxc_log_init(&log))
exit(err); exit(err);
}
c = lxc_container_new(my_args.name, my_args.lxcpath[0]); c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
if (!c) { if (!c) {
...@@ -195,12 +197,11 @@ int main(int argc, char *argv[]) ...@@ -195,12 +197,11 @@ int main(int argc, char *argv[])
goto out; goto out;
} }
if (my_args.argc == 0) { if (my_args.argc == 0)
if (!set_argv(c, &my_args)) { if (!set_argv(c, &my_args)) {
ERROR("Missing command to execute!"); ERROR("Missing command to execute!");
goto out; goto out;
} }
}
bret = lxc_config_define_load(&defines, c); bret = lxc_config_define_load(&defines, c);
if (!bret) if (!bret)
...@@ -244,13 +245,12 @@ int main(int argc, char *argv[]) ...@@ -244,13 +245,12 @@ int main(int argc, char *argv[])
if (c->daemonize) { if (c->daemonize) {
err = EXIT_SUCCESS; err = EXIT_SUCCESS;
} else { } else {
if (WIFEXITED(c->error_num)) { if (WIFEXITED(c->error_num))
err = WEXITSTATUS(c->error_num); err = WEXITSTATUS(c->error_num);
} else { else
/* Try to die with the same signal the task did. */ /* Try to die with the same signal the task did. */
kill(0, WTERMSIG(c->error_num)); kill(0, WTERMSIG(c->error_num));
} }
}
out: out:
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