From: Anthony Liguori <aliguori@cs.utexas.edu>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 2/2] Reinitialize monitor upon reconnect
Date: Sat, 16 Dec 2006 15:15:47 -0600 [thread overview]
Message-ID: <45846203.90401@cs.utexas.edu> (raw)
In-Reply-To: <45845F3B.30909@cs.utexas.edu>
[-- Attachment #1: Type: text/plain, Size: 1071 bytes --]
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
[-- Attachment #2: qemu-monitor-connect.diff --]
[-- Type: text/x-patch, Size: 2322 bytes --]
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);
prev parent reply other threads:[~2006-12-16 21:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-16 21:03 [Qemu-devel] [PATCH 0/2] Make the monitor a bit more program-friendly Anthony Liguori
2006-12-16 21:11 ` [Qemu-devel] [PATCH 1/2] Escape filenames in monitor Anthony Liguori
2006-12-17 15:41 ` Julian Seward
2006-12-17 16:36 ` Anthony Liguori
2006-12-16 21:15 ` Anthony Liguori [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=45846203.90401@cs.utexas.edu \
--to=aliguori@cs.utexas.edu \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).