#include <xenstore.h>
#include "xenctrl.h"
-#define ESCAPE_CHARACTER 0x1d
+#define DEFAULT_ESCAPE_CHARACTER 0x1d
static volatile sig_atomic_t received_signal = 0;
static char lockfile[sizeof (XEN_LOCK_DIR "/xenconsole.") + 8] = { 0 };
" -n, --num N use console number N\n"
" --type TYPE console type. must be 'pv', 'serial' or 'vuart'\n"
" --start-notify-fd N file descriptor used to notify parent\n"
+ " --escape E escape sequence to exit console\n"
, program);
}
}
static int console_loop(int fd, struct xs_handle *xs, char *pty_path,
- bool interactive)
+ bool interactive, char escape_character)
{
int ret, xs_fd = xs_fileno(xs), max_fd = -1;
char msg[60];
len = read(STDIN_FILENO, msg, sizeof(msg));
- if (len == 1 && msg[0] == ESCAPE_CHARACTER) {
+ if (len == 1 && msg[0] == escape_character) {
return 0;
}
{ "help", 0, 0, 'h' },
{ "start-notify-fd", 1, 0, 's' },
{ "interactive", 0, 0, 'i' },
+ { "escape", 1, 0, 'e' },
{ 0 },
};
console_type type = CONSOLE_INVAL;
bool interactive = 0;
const char *console_names = "serial, pv, vuart";
+ char escape_character = DEFAULT_ESCAPE_CHARACTER;
while((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) {
switch(ch) {
case 'i':
interactive = 1;
break;
+ case 'e':
+ if (optarg[0] == '^' && optarg[1] && optarg[2] == '\0')
+ escape_character = optarg[1] & 0x1f;
+ else if (optarg[0] && optarg[1] == '\0')
+ escape_character = optarg[0];
+ else {
+ fprintf(stderr, "Invalid escape argument\n");
+ exit(EINVAL);
+ }
+ break;
default:
fprintf(stderr, "Invalid argument\n");
fprintf(stderr, "Try `%s --help' for more information.\n",
close(start_notify_fd);
}
- console_loop(spty, xs, path, interactive);
+ console_loop(spty, xs, path, interactive, escape_character);
free(path);
free(dom_path);