[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 18/19] monitor: Introduce MONITOR_USE_READLINE fl
From: |
Jan Kiszka |
Subject: |
[Qemu-devel] [PATCH v2 18/19] monitor: Introduce MONITOR_USE_READLINE flag |
Date: |
Sat, 21 Feb 2009 19:29:17 +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.
Signed-off-by: Jan Kiszka <address@hidden>
---
migration.c | 7 +++++--
monitor.c | 47 +++++++++++++++++++++++++++++++++++++----------
monitor.h | 3 ++-
qemu-char.c | 2 +-
vl.c | 2 +-
5 files changed, 46 insertions(+), 15 deletions(-)
diff --git a/migration.c b/migration.c
index 15639c1..b3904b2 100644
--- a/migration.c
+++ b/migration.c
@@ -128,8 +128,11 @@ void do_info_migrate(Monitor *mon)
void migrate_fd_monitor_suspend(FdMigrationState *s)
{
s->mon_resume = cur_mon;
- monitor_suspend(cur_mon);
- dprintf("suspending monitor\n");
+ if (monitor_suspend(cur_mon) == 0)
+ dprintf("suspending monitor\n");
+ else
+ monitor_printf(cur_mon, "terminal does not allow synchronous "
+ "migration, continuing detached\n");
}
void migrate_fd_error(FdMigrationState *s)
diff --git a/monitor.c b/monitor.c
index 7cae863..a7f1cc1 100644
--- a/monitor.c
+++ b/monitor.c
@@ -97,11 +97,17 @@ static void monitor_read_command(Monitor *mon, int
show_prompt)
readline_show_prompt(mon->rs);
}
-static void monitor_read_password(Monitor *mon, ReadLineFunc *readline_func,
- void *opaque)
+static int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func,
+ void *opaque)
{
- readline_start(mon->rs, "Password: ", 1, readline_func, opaque);
- /* prompt is printed on return from the command handler */
+ if (mon->rs) {
+ readline_start(mon->rs, "Password: ", 1, readline_func, opaque);
+ /* prompt is printed on return from the command handler */
+ return 0;
+ } else {
+ monitor_printf(mon, "terminal does not support password prompting\n");
+ return -ENOTTY;
+ }
}
void monitor_flush(Monitor *mon)
@@ -373,6 +379,8 @@ static void do_info_history(Monitor *mon)
int i;
const char *str;
+ if (!mon->rs)
+ return;
i = 0;
for(;;) {
str = readline_get_history(mon->rs, i);
@@ -2859,8 +2867,15 @@ static void monitor_read(void *opaque, const uint8_t
*buf, int size)
cur_mon = opaque;
- for (i = 0; i < size; i++)
- readline_handle_byte(cur_mon->rs, buf[i]);
+ if (cur_mon->rs) {
+ for (i = 0; i < size; i++)
+ readline_handle_byte(cur_mon->rs, buf[i]);
+ } else {
+ if (size == 0 || buf[size - 1] != 0)
+ monitor_printf(cur_mon, "corrupted command\n");
+ else
+ monitor_handle_command(cur_mon, (char *)buf);
+ }
cur_mon = old_mon;
}
@@ -2872,13 +2887,18 @@ static void monitor_command_cb(Monitor *mon, const char
*cmdline, void *opaque)
monitor_resume(mon);
}
-void monitor_suspend(Monitor *mon)
+int monitor_suspend(Monitor *mon)
{
+ if (!mon->rs)
+ return -ENOTTY;
mon->suspend_cnt++;
+ return 0;
}
void monitor_resume(Monitor *mon)
{
+ if (!mon->rs)
+ return;
if (--mon->suspend_cnt == 0)
readline_show_prompt(mon->rs);
}
@@ -2926,8 +2946,10 @@ void monitor_init(CharDriverState *chr, int flags)
mon->flags = flags;
if (mon->chr->focus != 0)
mon->suspend_cnt = 1; /* mux'ed monitors start suspended */
- mon->rs = readline_init(mon, monitor_find_completion);
- monitor_read_command(mon, 0);
+ if (flags & MONITOR_USE_READLINE) {
+ mon->rs = readline_init(mon, monitor_find_completion);
+ monitor_read_command(mon, 0);
+ }
qemu_chr_add_handlers(chr, monitor_can_read, monitor_read, monitor_event,
mon);
@@ -2956,6 +2978,8 @@ void monitor_read_bdrv_key_start(Monitor *mon,
BlockDriverState *bs,
BlockDriverCompletionFunc *completion_cb,
void *opaque)
{
+ int err;
+
if (!bdrv_key_required(bs)) {
if (completion_cb)
completion_cb(opaque, 0);
@@ -2968,5 +2992,8 @@ void monitor_read_bdrv_key_start(Monitor *mon,
BlockDriverState *bs,
mon->password_completion_cb = completion_cb;
mon->password_opaque = opaque;
- monitor_read_password(mon, bdrv_password_cb, bs);
+ err = monitor_read_password(mon, bdrv_password_cb, bs);
+
+ if (err && completion_cb)
+ completion_cb(opaque, err);
}
diff --git a/monitor.h b/monitor.h
index 95a4060..13e8cc7 100644
--- a/monitor.h
+++ b/monitor.h
@@ -9,10 +9,11 @@ extern Monitor *cur_mon;
/* flags for monitor_init */
#define MONITOR_IS_DEFAULT 0x01
+#define MONITOR_USE_READLINE 0x02
void monitor_init(CharDriverState *chr, int flags);
-void monitor_suspend(Monitor *mon);
+int monitor_suspend(Monitor *mon);
void monitor_resume(Monitor *mon);
void monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs,
diff --git a/qemu-char.c b/qemu-char.c
index 8c5544c..26e8825 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2130,7 +2130,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 4c2a448..0b55051 100644
--- a/vl.c
+++ b/vl.c
@@ -5658,7 +5658,7 @@ int main(int argc, char **argv, char **envp)
qemu_chr_initial_reset();
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];
- [Qemu-devel] [PATCH v2 05/19] block: Introduce bdrv_get_encrypted_filename, (continued)
- [Qemu-devel] [PATCH v2 05/19] block: Introduce bdrv_get_encrypted_filename, Jan Kiszka, 2009/02/21
- [Qemu-devel] [PATCH v2 09/19] monitor: Simplify password input mode, Jan Kiszka, 2009/02/21
- [Qemu-devel] [PATCH v2 08/19] monitor: Rework early disk password inquiry, Jan Kiszka, 2009/02/21
- [Qemu-devel] [PATCH v2 07/19] monitor: Report encrypted disks in snapshot mode, Jan Kiszka, 2009/02/21
- [Qemu-devel] [PATCH v2 14/19] monitor: Drop banner hiding, Jan Kiszka, 2009/02/21
- [Qemu-devel] [PATCH v2 11/19] monitor: Rework modal password input, Jan Kiszka, 2009/02/21
- [Qemu-devel] [PATCH v2 19/19] monitor: Pass-through for gdbstub, Jan Kiszka, 2009/02/21
- [Qemu-devel] [PATCH v2 13/19] monitor: Rework terminal management, Jan Kiszka, 2009/02/21
- [Qemu-devel] [PATCH v2 10/19] monitor: Break out readline_show_prompt, Jan Kiszka, 2009/02/21
- [Qemu-devel] [PATCH v2 16/19] monitor: Decouple terminals, Jan Kiszka, 2009/02/21
- [Qemu-devel] [PATCH v2 18/19] monitor: Introduce MONITOR_USE_READLINE flag,
Jan Kiszka <=
- [Qemu-devel] [PATCH v2 15/19] monitor: Introduce ReadLineState, Jan Kiszka, 2009/02/21
- [Qemu-devel] [PATCH v2 12/19] monitor: Rework API, Jan Kiszka, 2009/02/21
- [Qemu-devel] [PATCH v2 17/19] monitor: Improve mux'ed console experience, Jan Kiszka, 2009/02/21
- Re: [Qemu-devel] [PATCH v2 00/19] monitor rework, Anthony Liguori, 2009/02/27