Commit cde76ee16adc33f29802596b3499e4fbfcabd8ff
1 parent
2724b180
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
Showing
5 changed files
with
46 additions
and
15 deletions
migration.c
| @@ -128,8 +128,11 @@ void do_info_migrate(Monitor *mon) | @@ -128,8 +128,11 @@ void do_info_migrate(Monitor *mon) | ||
| 128 | void migrate_fd_monitor_suspend(FdMigrationState *s) | 128 | void migrate_fd_monitor_suspend(FdMigrationState *s) |
| 129 | { | 129 | { |
| 130 | s->mon_resume = cur_mon; | 130 | s->mon_resume = cur_mon; |
| 131 | - monitor_suspend(cur_mon); | ||
| 132 | - dprintf("suspending monitor\n"); | 131 | + if (monitor_suspend(cur_mon) == 0) |
| 132 | + dprintf("suspending monitor\n"); | ||
| 133 | + else | ||
| 134 | + monitor_printf(cur_mon, "terminal does not allow synchronous " | ||
| 135 | + "migration, continuing detached\n"); | ||
| 133 | } | 136 | } |
| 134 | 137 | ||
| 135 | void migrate_fd_error(FdMigrationState *s) | 138 | void migrate_fd_error(FdMigrationState *s) |
monitor.c
| @@ -97,11 +97,17 @@ static void monitor_read_command(Monitor *mon, int show_prompt) | @@ -97,11 +97,17 @@ static void monitor_read_command(Monitor *mon, int show_prompt) | ||
| 97 | readline_show_prompt(mon->rs); | 97 | readline_show_prompt(mon->rs); |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | -static void monitor_read_password(Monitor *mon, ReadLineFunc *readline_func, | ||
| 101 | - void *opaque) | 100 | +static int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func, |
| 101 | + void *opaque) | ||
| 102 | { | 102 | { |
| 103 | - readline_start(mon->rs, "Password: ", 1, readline_func, opaque); | ||
| 104 | - /* prompt is printed on return from the command handler */ | 103 | + if (mon->rs) { |
| 104 | + readline_start(mon->rs, "Password: ", 1, readline_func, opaque); | ||
| 105 | + /* prompt is printed on return from the command handler */ | ||
| 106 | + return 0; | ||
| 107 | + } else { | ||
| 108 | + monitor_printf(mon, "terminal does not support password prompting\n"); | ||
| 109 | + return -ENOTTY; | ||
| 110 | + } | ||
| 105 | } | 111 | } |
| 106 | 112 | ||
| 107 | void monitor_flush(Monitor *mon) | 113 | void monitor_flush(Monitor *mon) |
| @@ -373,6 +379,8 @@ static void do_info_history(Monitor *mon) | @@ -373,6 +379,8 @@ static void do_info_history(Monitor *mon) | ||
| 373 | int i; | 379 | int i; |
| 374 | const char *str; | 380 | const char *str; |
| 375 | 381 | ||
| 382 | + if (!mon->rs) | ||
| 383 | + return; | ||
| 376 | i = 0; | 384 | i = 0; |
| 377 | for(;;) { | 385 | for(;;) { |
| 378 | str = readline_get_history(mon->rs, i); | 386 | str = readline_get_history(mon->rs, i); |
| @@ -2890,8 +2898,15 @@ static void monitor_read(void *opaque, const uint8_t *buf, int size) | @@ -2890,8 +2898,15 @@ static void monitor_read(void *opaque, const uint8_t *buf, int size) | ||
| 2890 | 2898 | ||
| 2891 | cur_mon = opaque; | 2899 | cur_mon = opaque; |
| 2892 | 2900 | ||
| 2893 | - for (i = 0; i < size; i++) | ||
| 2894 | - readline_handle_byte(cur_mon->rs, buf[i]); | 2901 | + if (cur_mon->rs) { |
| 2902 | + for (i = 0; i < size; i++) | ||
| 2903 | + readline_handle_byte(cur_mon->rs, buf[i]); | ||
| 2904 | + } else { | ||
| 2905 | + if (size == 0 || buf[size - 1] != 0) | ||
| 2906 | + monitor_printf(cur_mon, "corrupted command\n"); | ||
| 2907 | + else | ||
| 2908 | + monitor_handle_command(cur_mon, (char *)buf); | ||
| 2909 | + } | ||
| 2895 | 2910 | ||
| 2896 | cur_mon = old_mon; | 2911 | cur_mon = old_mon; |
| 2897 | } | 2912 | } |
| @@ -2903,13 +2918,18 @@ static void monitor_command_cb(Monitor *mon, const char *cmdline, void *opaque) | @@ -2903,13 +2918,18 @@ static void monitor_command_cb(Monitor *mon, const char *cmdline, void *opaque) | ||
| 2903 | monitor_resume(mon); | 2918 | monitor_resume(mon); |
| 2904 | } | 2919 | } |
| 2905 | 2920 | ||
| 2906 | -void monitor_suspend(Monitor *mon) | 2921 | +int monitor_suspend(Monitor *mon) |
| 2907 | { | 2922 | { |
| 2923 | + if (!mon->rs) | ||
| 2924 | + return -ENOTTY; | ||
| 2908 | mon->suspend_cnt++; | 2925 | mon->suspend_cnt++; |
| 2926 | + return 0; | ||
| 2909 | } | 2927 | } |
| 2910 | 2928 | ||
| 2911 | void monitor_resume(Monitor *mon) | 2929 | void monitor_resume(Monitor *mon) |
| 2912 | { | 2930 | { |
| 2931 | + if (!mon->rs) | ||
| 2932 | + return; | ||
| 2913 | if (--mon->suspend_cnt == 0) | 2933 | if (--mon->suspend_cnt == 0) |
| 2914 | readline_show_prompt(mon->rs); | 2934 | readline_show_prompt(mon->rs); |
| 2915 | } | 2935 | } |
| @@ -2957,8 +2977,10 @@ void monitor_init(CharDriverState *chr, int flags) | @@ -2957,8 +2977,10 @@ void monitor_init(CharDriverState *chr, int flags) | ||
| 2957 | mon->flags = flags; | 2977 | mon->flags = flags; |
| 2958 | if (mon->chr->focus != 0) | 2978 | if (mon->chr->focus != 0) |
| 2959 | mon->suspend_cnt = 1; /* mux'ed monitors start suspended */ | 2979 | mon->suspend_cnt = 1; /* mux'ed monitors start suspended */ |
| 2960 | - mon->rs = readline_init(mon, monitor_find_completion); | ||
| 2961 | - monitor_read_command(mon, 0); | 2980 | + if (flags & MONITOR_USE_READLINE) { |
| 2981 | + mon->rs = readline_init(mon, monitor_find_completion); | ||
| 2982 | + monitor_read_command(mon, 0); | ||
| 2983 | + } | ||
| 2962 | 2984 | ||
| 2963 | qemu_chr_add_handlers(chr, monitor_can_read, monitor_read, monitor_event, | 2985 | qemu_chr_add_handlers(chr, monitor_can_read, monitor_read, monitor_event, |
| 2964 | mon); | 2986 | mon); |
| @@ -2987,6 +3009,8 @@ void monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, | @@ -2987,6 +3009,8 @@ void monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, | ||
| 2987 | BlockDriverCompletionFunc *completion_cb, | 3009 | BlockDriverCompletionFunc *completion_cb, |
| 2988 | void *opaque) | 3010 | void *opaque) |
| 2989 | { | 3011 | { |
| 3012 | + int err; | ||
| 3013 | + | ||
| 2990 | if (!bdrv_key_required(bs)) { | 3014 | if (!bdrv_key_required(bs)) { |
| 2991 | if (completion_cb) | 3015 | if (completion_cb) |
| 2992 | completion_cb(opaque, 0); | 3016 | completion_cb(opaque, 0); |
| @@ -2999,5 +3023,8 @@ void monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, | @@ -2999,5 +3023,8 @@ void monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, | ||
| 2999 | mon->password_completion_cb = completion_cb; | 3023 | mon->password_completion_cb = completion_cb; |
| 3000 | mon->password_opaque = opaque; | 3024 | mon->password_opaque = opaque; |
| 3001 | 3025 | ||
| 3002 | - monitor_read_password(mon, bdrv_password_cb, bs); | 3026 | + err = monitor_read_password(mon, bdrv_password_cb, bs); |
| 3027 | + | ||
| 3028 | + if (err && completion_cb) | ||
| 3029 | + completion_cb(opaque, err); | ||
| 3003 | } | 3030 | } |
monitor.h
| @@ -9,10 +9,11 @@ extern Monitor *cur_mon; | @@ -9,10 +9,11 @@ extern Monitor *cur_mon; | ||
| 9 | 9 | ||
| 10 | /* flags for monitor_init */ | 10 | /* flags for monitor_init */ |
| 11 | #define MONITOR_IS_DEFAULT 0x01 | 11 | #define MONITOR_IS_DEFAULT 0x01 |
| 12 | +#define MONITOR_USE_READLINE 0x02 | ||
| 12 | 13 | ||
| 13 | void monitor_init(CharDriverState *chr, int flags); | 14 | void monitor_init(CharDriverState *chr, int flags); |
| 14 | 15 | ||
| 15 | -void monitor_suspend(Monitor *mon); | 16 | +int monitor_suspend(Monitor *mon); |
| 16 | void monitor_resume(Monitor *mon); | 17 | void monitor_resume(Monitor *mon); |
| 17 | 18 | ||
| 18 | void monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, | 19 | void monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, |
qemu-char.c
| @@ -2130,7 +2130,7 @@ CharDriverState *qemu_chr_open(const char *label, const char *filename, void (*i | @@ -2130,7 +2130,7 @@ CharDriverState *qemu_chr_open(const char *label, const char *filename, void (*i | ||
| 2130 | chr = qemu_chr_open(label, p, NULL); | 2130 | chr = qemu_chr_open(label, p, NULL); |
| 2131 | if (chr) { | 2131 | if (chr) { |
| 2132 | chr = qemu_chr_open_mux(chr); | 2132 | chr = qemu_chr_open_mux(chr); |
| 2133 | - monitor_init(chr, 0); | 2133 | + monitor_init(chr, MONITOR_USE_READLINE); |
| 2134 | } else { | 2134 | } else { |
| 2135 | printf("Unable to open driver: %s\n", p); | 2135 | printf("Unable to open driver: %s\n", p); |
| 2136 | } | 2136 | } |
vl.c
| @@ -5684,7 +5684,7 @@ int main(int argc, char **argv, char **envp) | @@ -5684,7 +5684,7 @@ int main(int argc, char **argv, char **envp) | ||
| 5684 | qemu_chr_initial_reset(); | 5684 | qemu_chr_initial_reset(); |
| 5685 | 5685 | ||
| 5686 | if (monitor_device && monitor_hd) | 5686 | if (monitor_device && monitor_hd) |
| 5687 | - monitor_init(monitor_hd, MONITOR_IS_DEFAULT); | 5687 | + monitor_init(monitor_hd, MONITOR_USE_READLINE | MONITOR_IS_DEFAULT); |
| 5688 | 5688 | ||
| 5689 | for(i = 0; i < MAX_SERIAL_PORTS; i++) { | 5689 | for(i = 0; i < MAX_SERIAL_PORTS; i++) { |
| 5690 | const char *devname = serial_devices[i]; | 5690 | const char *devname = serial_devices[i]; |