Unverified Commit d0e1b257 by 2xsec Committed by Christian Brauner

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

Signed-off-by: 's avatar2xsec <dh48.jeong@samsung.com>
parent 83a5624a
...@@ -44,28 +44,8 @@ ...@@ -44,28 +44,8 @@
lxc_log_define(lxc_console, lxc); lxc_log_define(lxc_console, lxc);
static char etoc(const char *expr) static int my_parser(struct lxc_arguments *args, int c, char *arg);
{ static char etoc(const char *expr);
/* returns "control code" of given expression */
char c = expr[0] == '^' ? expr[1] : expr[0];
return 1 + ((c > 'Z') ? (c - 'a') : (c - 'Z'));
}
static int my_parser(struct lxc_arguments *args, int c, char *arg)
{
switch (c) {
case 't':
if (lxc_safe_uint(arg, &args->ttynum) < 0)
return -1;
break;
case 'e':
args->escape = etoc(arg);
break;
}
return 0;
}
static const struct option my_longopts[] = { static const struct option my_longopts[] = {
{"tty", required_argument, 0, 't'}, {"tty", required_argument, 0, 't'},
...@@ -74,8 +54,8 @@ static const struct option my_longopts[] = { ...@@ -74,8 +54,8 @@ static const struct option my_longopts[] = {
}; };
static struct lxc_arguments my_args = { static struct lxc_arguments my_args = {
.progname = "lxc-console", .progname = "lxc-console",
.help = "\ .help = "\
--name=NAME [--tty NUMBER]\n\ --name=NAME [--tty NUMBER]\n\
\n\ \n\
lxc-console logs on the container with the identifier NAME\n\ lxc-console logs on the container with the identifier NAME\n\
...@@ -85,35 +65,56 @@ Options :\n\ ...@@ -85,35 +65,56 @@ Options :\n\
-t, --tty=NUMBER console tty number\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", --rcfile=FILE Load configuration file FILE\n",
.options = my_longopts, .options = my_longopts,
.parser = my_parser, .parser = my_parser,
.checker = NULL, .checker = NULL,
.ttynum = -1, .log_priority = "ERROR",
.escape = 1, .log_file = "none",
.ttynum = -1,
.escape = 1,
}; };
static int my_parser(struct lxc_arguments *args, int c, char *arg)
{
switch (c) {
case 't':
if (lxc_safe_uint(arg, &args->ttynum) < 0)
return -1;
break;
case 'e':
args->escape = etoc(arg);
break;
}
return 0;
}
static char etoc(const char *expr)
{
/* returns "control code" of given expression */
char c = expr[0] == '^' ? expr[1] : expr[0];
return 1 + ((c > 'Z') ? (c - 'a') : (c - 'Z'));
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int ret; int ret;
struct lxc_container *c; struct lxc_container *c;
struct lxc_log log; struct lxc_log log;
ret = lxc_arguments_parse(&my_args, argc, argv); if (lxc_arguments_parse(&my_args, argc, argv))
if (ret)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
/* Only create log if explicitly instructed */ log.name = my_args.name;
if (my_args.log_file || my_args.log_priority) { log.file = my_args.log_file;
log.name = my_args.name; log.level = my_args.log_priority;
log.file = my_args.log_file; log.prefix = my_args.progname;
log.level = my_args.log_priority; log.quiet = my_args.quiet;
log.prefix = my_args.progname; log.lxcpath = my_args.lxcpath[0];
log.quiet = my_args.quiet;
log.lxcpath = my_args.lxcpath[0];
if (lxc_log_init(&log)) if (lxc_log_init(&log))
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
}
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) {
......
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