Commit 871271615108fd58273423d98b7cefe08e6f75a0
1 parent
376253ec
monitor: Rework terminal management (Jan Kiszka)
Remove the static MAX_MON limit by managing monitor terminals in a linked list. 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@6712 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
23 additions
and
20 deletions
monitor.c
... | ... | @@ -67,8 +67,12 @@ typedef struct mon_cmd_t { |
67 | 67 | const char *help; |
68 | 68 | } mon_cmd_t; |
69 | 69 | |
70 | -#define MAX_MON 4 | |
71 | -static CharDriverState *monitor_hd[MAX_MON]; | |
70 | +struct Monitor { | |
71 | + CharDriverState *chr; | |
72 | + LIST_ENTRY(Monitor) entry; | |
73 | +}; | |
74 | + | |
75 | +static LIST_HEAD(mon_list, Monitor) mon_list; | |
72 | 76 | static int hide_banner; |
73 | 77 | |
74 | 78 | static const mon_cmd_t mon_cmds[]; |
... | ... | @@ -79,7 +83,7 @@ static int term_outbuf_index; |
79 | 83 | static BlockDriverCompletionFunc *password_completion_cb; |
80 | 84 | static void *password_opaque; |
81 | 85 | |
82 | -Monitor *cur_mon; | |
86 | +Monitor *cur_mon = NULL; | |
83 | 87 | |
84 | 88 | static void monitor_start_input(void); |
85 | 89 | |
... | ... | @@ -93,11 +97,13 @@ static void monitor_read_password(Monitor *mon, ReadLineFunc *readline_func, |
93 | 97 | |
94 | 98 | void monitor_flush(Monitor *mon) |
95 | 99 | { |
96 | - int i; | |
100 | + Monitor *m; | |
101 | + | |
97 | 102 | if (term_outbuf_index > 0) { |
98 | - for (i = 0; i < MAX_MON; i++) | |
99 | - if (monitor_hd[i] && monitor_hd[i]->focus == 0) | |
100 | - qemu_chr_write(monitor_hd[i], term_outbuf, term_outbuf_index); | |
103 | + LIST_FOREACH(m, &mon_list, entry) { | |
104 | + if (m->chr->focus == 0) | |
105 | + qemu_chr_write(m->chr, term_outbuf, term_outbuf_index); | |
106 | + } | |
101 | 107 | term_outbuf_index = 0; |
102 | 108 | } |
103 | 109 | } |
... | ... | @@ -2921,27 +2927,24 @@ static int is_first_init = 1; |
2921 | 2927 | |
2922 | 2928 | void monitor_init(CharDriverState *chr, int show_banner) |
2923 | 2929 | { |
2924 | - int i; | |
2930 | + Monitor *mon; | |
2925 | 2931 | |
2926 | 2932 | if (is_first_init) { |
2927 | 2933 | key_timer = qemu_new_timer(vm_clock, release_keys, NULL); |
2928 | - if (!key_timer) | |
2929 | - return; | |
2930 | - for (i = 0; i < MAX_MON; i++) { | |
2931 | - monitor_hd[i] = NULL; | |
2932 | - } | |
2933 | 2934 | is_first_init = 0; |
2934 | 2935 | } |
2935 | - for (i = 0; i < MAX_MON; i++) { | |
2936 | - if (monitor_hd[i] == NULL) { | |
2937 | - monitor_hd[i] = chr; | |
2938 | - break; | |
2939 | - } | |
2940 | - } | |
2936 | + | |
2937 | + mon = qemu_mallocz(sizeof(*mon)); | |
2941 | 2938 | |
2942 | 2939 | hide_banner = !show_banner; |
2943 | 2940 | |
2944 | - qemu_chr_add_handlers(chr, term_can_read, term_read, term_event, cur_mon); | |
2941 | + mon->chr = chr; | |
2942 | + | |
2943 | + qemu_chr_add_handlers(chr, term_can_read, term_read, term_event, mon); | |
2944 | + | |
2945 | + LIST_INSERT_HEAD(&mon_list, mon, entry); | |
2946 | + if (!cur_mon) | |
2947 | + cur_mon = mon; | |
2945 | 2948 | |
2946 | 2949 | readline_start("", 0, monitor_command_cb, NULL); |
2947 | 2950 | } | ... | ... |