qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 2/2] Reinitialize monitor upon reconnect


From: Anthony Liguori
Subject: [Qemu-devel] [PATCH 2/2] Reinitialize monitor upon reconnect
Date: Sat, 16 Dec 2006 15:15:47 -0600
User-agent: Thunderbird 1.5.0.8 (X11/20061115)

If you expose the monitor on a character device that support reconnecting, it becomes difficult to deterministically execute commands. For instance, one person may connect and send a partial command in which case reconnecting may result in your command not being what you expect.

Furthermore, not knowing what to expect when you connect initially is annoying. There may be a prompt, there may be nothing, or there may be a banner and prompt.

This patch adds a new event that's signaled whenever a character device supporting reconnecting reconnects. For the monitor, this event causes the monitor to be reset.

This means no matter when you connect to the monitor (or reconnect), you'll always have deterministic behavior (the banner is printed with a new prompt).

Please note, if you don't use the nowait option, you'll see the banner twice the first time you connect. I'm not sure I really see the value of not always doing nowait (particularly since there is -S). Perhaps someone can shed light on what the use case is?

Regards,

Anthony Liguori
diff -r 3ce6d719bfc0 monitor.c
--- a/monitor.c Sat Dec 16 14:34:25 2006 -0600
+++ b/monitor.c Sat Dec 16 14:57:03 2006 -0600
@@ -2388,6 +2388,16 @@ static void term_read(void *opaque, cons
         readline_handle_byte(buf[i]);
 }
 
+static void term_event(void *opaque, int event)
+{
+    if (event != CHR_EVENT_RESET)
+       return;
+
+    term_printf("QEMU %s monitor - type 'help' for more information\n",
+               QEMU_VERSION);
+    readline_reset();
+}
+
 static void monitor_start_input(void);
 
 static void monitor_handle_command1(void *opaque, const char *cmdline)
@@ -2410,6 +2420,7 @@ void monitor_init(CharDriverState *hd, i
     }
     qemu_chr_add_read_handler(hd, term_can_read, term_read, NULL);
     monitor_start_input();
+    qemu_chr_add_event_handler(hd, term_event);
 }
 
 /* XXX: use threads ? */
diff -r 3ce6d719bfc0 readline.c
--- a/readline.c        Sat Dec 16 14:34:25 2006 -0600
+++ b/readline.c        Sat Dec 16 14:37:52 2006 -0600
@@ -415,6 +415,11 @@ void readline_start(const char *prompt, 
     term_show_prompt();
 }
 
+void readline_reset(void)
+{
+    term_show_prompt();
+}
+
 const char *readline_get_history(unsigned int index)
 {
     if (index >= TERM_MAX_CMDS)
diff -r 3ce6d719bfc0 vl.c
--- a/vl.c      Sat Dec 16 14:34:25 2006 -0600
+++ b/vl.c      Sat Dec 16 14:57:20 2006 -0600
@@ -2399,6 +2399,8 @@ static void tcp_chr_connect(void *opaque
     s->connected = 1;
     qemu_set_fd_handler2(s->fd, tcp_chr_read_poll,
                          tcp_chr_read, NULL, chr);
+    if (chr->chr_event)
+           chr->chr_event(chr, CHR_EVENT_RESET);
 }
 
 #define IACSET(x,a,b,c) x[0] = a; x[1] = b; x[2] = c;
diff -r 3ce6d719bfc0 vl.h
--- a/vl.h      Sat Dec 16 14:34:25 2006 -0600
+++ b/vl.h      Sat Dec 16 14:42:55 2006 -0600
@@ -240,7 +240,7 @@ void qemu_del_wait_object(HANDLE handle,
 
 #define CHR_EVENT_BREAK 0 /* serial break char */
 #define CHR_EVENT_FOCUS 1 /* focus to this terminal (modal input needed) */
-
+#define CHR_EVENT_RESET 2 /* new connection established */
 
 
 #define CHR_IOCTL_SERIAL_SET_PARAMS   1
@@ -1334,6 +1334,7 @@ const char *readline_get_history(unsigne
 const char *readline_get_history(unsigned int index);
 void readline_start(const char *prompt, int is_password,
                     ReadLineFunc *readline_func, void *opaque);
+void readline_reset(void);
 
 void kqemu_record_dump(void);
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]