monitor: Introduce MONITOR_USE_READLINE flag (Jan Kiszka)

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 <jan.kiszka@siemens.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6717 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
aliguori 2009-03-05 23:01:51 +00:00
parent 2724b1806a
commit cde76ee16a
5 changed files with 46 additions and 15 deletions

View file

@ -128,8 +128,11 @@ void do_info_migrate(Monitor *mon)
void migrate_fd_monitor_suspend(FdMigrationState *s) void migrate_fd_monitor_suspend(FdMigrationState *s)
{ {
s->mon_resume = cur_mon; s->mon_resume = cur_mon;
monitor_suspend(cur_mon); if (monitor_suspend(cur_mon) == 0)
dprintf("suspending monitor\n"); dprintf("suspending monitor\n");
else
monitor_printf(cur_mon, "terminal does not allow synchronous "
"migration, continuing detached\n");
} }
void migrate_fd_error(FdMigrationState *s) void migrate_fd_error(FdMigrationState *s)

View file

@ -97,11 +97,17 @@ static void monitor_read_command(Monitor *mon, int show_prompt)
readline_show_prompt(mon->rs); readline_show_prompt(mon->rs);
} }
static void monitor_read_password(Monitor *mon, ReadLineFunc *readline_func, static int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func,
void *opaque) void *opaque)
{ {
readline_start(mon->rs, "Password: ", 1, readline_func, opaque); if (mon->rs) {
/* prompt is printed on return from the command handler */ 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) void monitor_flush(Monitor *mon)
@ -373,6 +379,8 @@ static void do_info_history(Monitor *mon)
int i; int i;
const char *str; const char *str;
if (!mon->rs)
return;
i = 0; i = 0;
for(;;) { for(;;) {
str = readline_get_history(mon->rs, i); str = readline_get_history(mon->rs, i);
@ -2890,8 +2898,15 @@ static void monitor_read(void *opaque, const uint8_t *buf, int size)
cur_mon = opaque; cur_mon = opaque;
for (i = 0; i < size; i++) if (cur_mon->rs) {
readline_handle_byte(cur_mon->rs, buf[i]); 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; cur_mon = old_mon;
} }
@ -2903,13 +2918,18 @@ static void monitor_command_cb(Monitor *mon, const char *cmdline, void *opaque)
monitor_resume(mon); monitor_resume(mon);
} }
void monitor_suspend(Monitor *mon) int monitor_suspend(Monitor *mon)
{ {
if (!mon->rs)
return -ENOTTY;
mon->suspend_cnt++; mon->suspend_cnt++;
return 0;
} }
void monitor_resume(Monitor *mon) void monitor_resume(Monitor *mon)
{ {
if (!mon->rs)
return;
if (--mon->suspend_cnt == 0) if (--mon->suspend_cnt == 0)
readline_show_prompt(mon->rs); readline_show_prompt(mon->rs);
} }
@ -2957,8 +2977,10 @@ void monitor_init(CharDriverState *chr, int flags)
mon->flags = flags; mon->flags = flags;
if (mon->chr->focus != 0) if (mon->chr->focus != 0)
mon->suspend_cnt = 1; /* mux'ed monitors start suspended */ mon->suspend_cnt = 1; /* mux'ed monitors start suspended */
mon->rs = readline_init(mon, monitor_find_completion); if (flags & MONITOR_USE_READLINE) {
monitor_read_command(mon, 0); 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, qemu_chr_add_handlers(chr, monitor_can_read, monitor_read, monitor_event,
mon); mon);
@ -2987,6 +3009,8 @@ void monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs,
BlockDriverCompletionFunc *completion_cb, BlockDriverCompletionFunc *completion_cb,
void *opaque) void *opaque)
{ {
int err;
if (!bdrv_key_required(bs)) { if (!bdrv_key_required(bs)) {
if (completion_cb) if (completion_cb)
completion_cb(opaque, 0); completion_cb(opaque, 0);
@ -2999,5 +3023,8 @@ void monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs,
mon->password_completion_cb = completion_cb; mon->password_completion_cb = completion_cb;
mon->password_opaque = opaque; 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);
} }

View file

@ -9,10 +9,11 @@ extern Monitor *cur_mon;
/* flags for monitor_init */ /* flags for monitor_init */
#define MONITOR_IS_DEFAULT 0x01 #define MONITOR_IS_DEFAULT 0x01
#define MONITOR_USE_READLINE 0x02
void monitor_init(CharDriverState *chr, int flags); void monitor_init(CharDriverState *chr, int flags);
void monitor_suspend(Monitor *mon); int monitor_suspend(Monitor *mon);
void monitor_resume(Monitor *mon); void monitor_resume(Monitor *mon);
void monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, void monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs,

View file

@ -2130,7 +2130,7 @@ CharDriverState *qemu_chr_open(const char *label, const char *filename, void (*i
chr = qemu_chr_open(label, p, NULL); chr = qemu_chr_open(label, p, NULL);
if (chr) { if (chr) {
chr = qemu_chr_open_mux(chr); chr = qemu_chr_open_mux(chr);
monitor_init(chr, 0); monitor_init(chr, MONITOR_USE_READLINE);
} else { } else {
printf("Unable to open driver: %s\n", p); printf("Unable to open driver: %s\n", p);
} }

2
vl.c
View file

@ -5684,7 +5684,7 @@ int main(int argc, char **argv, char **envp)
qemu_chr_initial_reset(); qemu_chr_initial_reset();
if (monitor_device && monitor_hd) 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++) { for(i = 0; i < MAX_SERIAL_PORTS; i++) {
const char *devname = serial_devices[i]; const char *devname = serial_devices[i];