Commit 84a24de2 by Taisuke Yamada Committed by Daniel Lezcano

Added -e to lxc-console to change command character (defaults to '^a')

I noticed lxc-console uses '^a' as command-mode prefix to escape out of console session, so created a patch to make it configurable. With this, you can do lxc-console -n foo -e ^t and exit the session with 'Ctrl+t q'. For emacs-binding addicts (like me), it's always nice to let shell handle '^a' as 'beginning-of-line' command... Signed-off-by: 's avatarTaisuke Yamada <tai@rakugaki.org> Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent 5fa5aa7c
...@@ -51,6 +51,7 @@ struct lxc_arguments { ...@@ -51,6 +51,7 @@ struct lxc_arguments {
/* for lxc-console */ /* for lxc-console */
int ttynum; int ttynum;
char escape;
/* for lxc-wait */ /* for lxc-wait */
char *states; char *states;
......
...@@ -46,16 +46,25 @@ ...@@ -46,16 +46,25 @@
lxc_log_define(lxc_console_ui, lxc_console); lxc_log_define(lxc_console_ui, lxc_console);
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) static int my_parser(struct lxc_arguments* args, int c, char* arg)
{ {
switch (c) { switch (c) {
case 't': args->ttynum = atoi(arg); break; case 't': args->ttynum = atoi(arg); break;
case 'e': args->escape = etoc(arg); break;
} }
return 0; return 0;
} }
static const struct option my_longopts[] = { static const struct option my_longopts[] = {
{"tty", required_argument, 0, 't'}, {"tty", required_argument, 0, 't'},
{"escape", required_argument, 0, 'e'},
LXC_COMMON_OPTIONS LXC_COMMON_OPTIONS
}; };
...@@ -67,12 +76,14 @@ static struct lxc_arguments my_args = { ...@@ -67,12 +76,14 @@ static struct lxc_arguments my_args = {
lxc-console logs on the container with the identifier NAME\n\ lxc-console logs on the container with the identifier NAME\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\
-t, --tty=NUMBER console tty number\n", -t, --tty=NUMBER console tty number\n\
-e, --escape=PREFIX prefix for escape command\n",
.options = my_longopts, .options = my_longopts,
.parser = my_parser, .parser = my_parser,
.checker = NULL, .checker = NULL,
.ttynum = -1, .ttynum = -1,
.escape = 1,
}; };
static int master = -1; static int master = -1;
...@@ -131,7 +142,8 @@ int main(int argc, char *argv[]) ...@@ -131,7 +142,8 @@ int main(int argc, char *argv[])
if (err) if (err)
goto out; goto out;
fprintf(stderr, "\nType <Ctrl+a q> to exit the console\n"); fprintf(stderr, "\nType <Ctrl+%c q> to exit the console\n",
'a' + my_args.escape - 1);
setsid(); setsid();
signal(SIGWINCH, sigwinch); signal(SIGWINCH, sigwinch);
...@@ -167,7 +179,7 @@ int main(int argc, char *argv[]) ...@@ -167,7 +179,7 @@ int main(int argc, char *argv[])
} }
/* we want to exit the console with Ctrl+a q */ /* we want to exit the console with Ctrl+a q */
if (c == 1) { if (c == my_args.escape) {
wait4q = !wait4q; wait4q = !wait4q;
continue; continue;
} }
......
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