[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 16/17] monitor: Introduce MONITOR_USE_READLINE flag
From: |
Jan Kiszka |
Subject: |
[Qemu-devel] [PATCH 16/17] monitor: Introduce MONITOR_USE_READLINE flag |
Date: |
Sat, 07 Feb 2009 19:16:29 +0100 |
User-agent: |
StGIT/0.14.2 |
This allows to create monitor terminals that do not make use of the
interactive readline back-end but rather send complete commands. The
pass-through monitor interface of the gdbstub will be an example for
such terminals.
Signed-off-by: Jan Kiszka <address@hidden>
---
migration.c | 6 +++++-
monitor.c | 50 +++++++++++++++++++++++++++++++++++++++-----------
monitor.h | 1 +
qemu-char.c | 2 +-
vl.c | 2 +-
5 files changed, 47 insertions(+), 14 deletions(-)
diff --git a/migration.c b/migration.c
index 18c1492..c9365d7 100644
--- a/migration.c
+++ b/migration.c
@@ -128,7 +128,11 @@ void do_info_migrate(void)
void migrate_fd_monitor_suspend(FdMigrationState *s)
{
s->mon_resume_handle = monitor_suspend();
- dprintf("suspending monitor\n");
+ if (s->mon_resume_handle)
+ dprintf("suspending monitor\n");
+ else
+ monitor_printf("terminal does not allow synchronous migration, "
+ "continuing detached\n");
}
void migrate_fd_error(FdMigrationState *s)
diff --git a/monitor.c b/monitor.c
index 2306b10..364b13d 100644
--- a/monitor.c
+++ b/monitor.c
@@ -95,10 +95,16 @@ static void monitor_read_command(MonitorTerm *term, int
show_prompt)
readline_show_prompt(term->rs);
}
-static void monitor_read_password(ReadLineFunc *readline_func, void *opaque)
+static int monitor_read_password(ReadLineFunc *readline_func, void *opaque)
{
- readline_start(cur_term->rs, "Password: ", 1, readline_func, opaque);
- /* prompt is printed on return from the command handler */
+ if (cur_term->rs) {
+ readline_start(cur_term->rs, "Password: ", 1, readline_func, opaque);
+ /* prompt is printed on return from the command handler */
+ return 0;
+ } else {
+ monitor_printf("terminal does not support password prompting\n");
+ return -ENOTTY;
+ }
}
void monitor_flush(void)
@@ -385,6 +391,9 @@ static void do_info_history (void)
int i;
const char *str;
+ if (!cur_term->rs)
+ return;
+
i = 0;
for(;;) {
str = readline_get_history(cur_term->rs, i);
@@ -2833,8 +2842,15 @@ static void term_read(void *opaque, const uint8_t *buf,
int size)
cur_term = opaque;
- for (i = 0; i < size; i++)
- readline_handle_byte(cur_term->rs, buf[i]);
+ if (cur_term->rs) {
+ for (i = 0; i < size; i++)
+ readline_handle_byte(cur_term->rs, buf[i]);
+ } else {
+ if (size == 0 || buf[size - 1] != 0)
+ monitor_printf("corrupted command\n");
+ else
+ monitor_handle_command((char *)buf);
+ }
cur_term = old_term;
}
@@ -2848,6 +2864,9 @@ static void monitor_command_cb(void *opaque, const char
*cmdline)
void *monitor_suspend(void)
{
+ if (!cur_term->rs)
+ return NULL;
+
cur_term->suspend_cnt++;
return cur_term;
}
@@ -2858,8 +2877,10 @@ void monitor_resume(void *handle)
cur_term = handle;
- if (--cur_term->suspend_cnt == 0)
- readline_show_prompt(cur_term->rs);
+ if (cur_term->rs) {
+ if (--cur_term->suspend_cnt == 0)
+ readline_show_prompt(cur_term->rs);
+ }
cur_term = old_term;
}
@@ -2907,10 +2928,12 @@ void monitor_init(CharDriverState *chr, int flags)
term = qemu_mallocz(sizeof(*term));
term->chr = chr;
- term->flags = flags;
+ term->flags = flags & (MONITOR_IS_DEFAULT | MONITOR_USE_READLINE);
term->suspend_cnt = 1; /* resume on reset */
- term->rs = readline_init(monitor_find_completion);
- monitor_read_command(term, 0);
+ if (flags & MONITOR_USE_READLINE) {
+ term->rs = readline_init(monitor_find_completion);
+ monitor_read_command(term, 0);
+ }
qemu_chr_add_handlers(chr, term_can_read, term_read, term_event, term);
@@ -2938,6 +2961,8 @@ void monitor_read_bdrv_key_start(BlockDriverState *bs,
BlockDriverCompletionFunc *completion_cb,
void *opaque)
{
+ int err;
+
if (!bdrv_key_required(bs)) {
if (completion_cb)
completion_cb(opaque, 0);
@@ -2950,5 +2975,8 @@ void monitor_read_bdrv_key_start(BlockDriverState *bs,
cur_term->password_completion_cb = completion_cb;
cur_term->password_opaque = opaque;
- monitor_read_password(bdrv_password_cb, bs);
+ err = monitor_read_password(bdrv_password_cb, bs);
+
+ if (err && completion_cb)
+ completion_cb(opaque, err);
}
diff --git a/monitor.h b/monitor.h
index 7af267d..bb2a06a 100644
--- a/monitor.h
+++ b/monitor.h
@@ -6,6 +6,7 @@
/* flags for monitor_init */
#define MONITOR_IS_DEFAULT 0x01
+#define MONITOR_USE_READLINE 0x02
void monitor_init(CharDriverState *chr, int flags);
void *monitor_suspend(void);
diff --git a/qemu-char.c b/qemu-char.c
index d107c53..b7480a0 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2102,7 +2102,7 @@ CharDriverState *qemu_chr_open(const char *label, const
char *filename, void (*i
chr = qemu_chr_open(label, p, NULL);
if (chr) {
chr = qemu_chr_open_mux(chr);
- monitor_init(chr, 0);
+ monitor_init(chr, MONITOR_USE_READLINE);
} else {
printf("Unable to open driver: %s\n", p);
}
diff --git a/vl.c b/vl.c
index a80a25b..d569e6b 100644
--- a/vl.c
+++ b/vl.c
@@ -5594,7 +5594,7 @@ int main(int argc, char **argv, char **envp)
text_consoles_set_display(display_state);
if (monitor_device && monitor_hd)
- monitor_init(monitor_hd, MONITOR_IS_DEFAULT);
+ monitor_init(monitor_hd, MONITOR_USE_READLINE | MONITOR_IS_DEFAULT);
for(i = 0; i < MAX_SERIAL_PORTS; i++) {
const char *devname = serial_devices[i];
- Re: [Qemu-devel] [PATCH 04/17] monitor: Report encrypted disks in snapshot mode, (continued)
- [Qemu-devel] [PATCH 01/17] block: Polish error handling of brdv_open2, Jan Kiszka, 2009/02/07
- [Qemu-devel] [PATCH 09/17] monitor: Simplify password input mode, Jan Kiszka, 2009/02/07
- [Qemu-devel] [PATCH 10/17] monitor: Rework terminal management, Jan Kiszka, 2009/02/07
- [Qemu-devel] [PATCH 15/17] monitor: Improve mux'ed console experience, Jan Kiszka, 2009/02/07
- [Qemu-devel] [PATCH 16/17] monitor: Introduce MONITOR_USE_READLINE flag,
Jan Kiszka <=
- [Qemu-devel] [PATCH 14/17] monitor: Decouple terminals, Jan Kiszka, 2009/02/07
[Qemu-devel] [PATCH 17/17] monitor: Pass-through for gdbstub, Jan Kiszka, 2009/02/07
[Qemu-devel] [PATCH 13/17] monitor: Introduce ReadLineState, Jan Kiszka, 2009/02/07
[Qemu-devel] [PATCH 07/17] monitor: Introduce monitor.h and readline.h, Jan Kiszka, 2009/02/07
[Qemu-devel] [PATCH 12/17] monitor: Rework modal password input, Jan Kiszka, 2009/02/07
[Qemu-devel] [PATCH 06/17] char-mux: Use separate input buffers, Jan Kiszka, 2009/02/07