[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 02/21] libqtest: Work around a "QMP wants a newl
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH 02/21] libqtest: Work around a "QMP wants a newline" bug |
Date: |
Thu, 23 Feb 2017 16:59:47 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 |
On 02/23/2017 03:44 PM, Markus Armbruster wrote:
> The next commit is going to add a test that calls qmp("null").
> Curiously, this hangs. Here's why.
>
> qmp_fd_sendv() doesn't send newlines. Not even when @fmt contains
> some. At first glance, the QMP parser seems to be fine with that.
> However, it turns out that it fails to react to input until it sees
> either a newline, an object or an array. To reproduce, feed to a QMP
> monitor like this:
>
>
> Work around this QMP bug by having qmp_fd_sendv() append a newline.
>
> Signed-off-by: Markus Armbruster <address@hidden>
> ---
> tests/libqtest.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> +++ b/tests/libqtest.c
> @@ -442,14 +442,20 @@ void qmp_fd_sendv(int fd, const char *fmt, va_list ap)
> if (qobj) {
> int log = getenv("QTEST_LOG") != NULL;
> QString *qstr = qobject_to_json(qobj);
> - const char *str = qstring_get_str(qstr);
> - size_t size = qstring_get_length(qstr);
> + const char *str;
> +
> + /*
> + * BUG: QMP doesn't react to input until it sees a newline, an
> + * object, or an array. Work-around: give it a newline.
> + */
> + qstring_append_chr(qstr, '\n');
> + str = qstring_get_str(qstr);
>
> if (log) {
> fprintf(stderr, "%s", str);
Bonus - the log now has newlines, too :)
> }
> /* Send QMP request */
> - socket_send(fd, str, size);
> + socket_send(fd, str, qstring_get_length(qstr));
Reviewed-by: Eric Blake <address@hidden>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
- [Qemu-devel] [PATCH 01/21] qga: Fix crash on non-dictionary QMP argument, (continued)
- [Qemu-devel] [PATCH 01/21] qga: Fix crash on non-dictionary QMP argument, Markus Armbruster, 2017/02/23
- [Qemu-devel] [PATCH 14/21] qapi: Make string input and opts visitor require non-null input, Markus Armbruster, 2017/02/23
- [Qemu-devel] [PATCH 08/21] qmp: Improve QMP dispatch error messages, Markus Armbruster, 2017/02/23
- [Qemu-devel] [PATCH 02/21] libqtest: Work around a "QMP wants a newline" bug, Markus Armbruster, 2017/02/23
- Re: [Qemu-devel] [PATCH 02/21] libqtest: Work around a "QMP wants a newline" bug,
Eric Blake <=
- [Qemu-devel] [PATCH 05/21] qmp: Clean up how we enforce capability negotiation, Markus Armbruster, 2017/02/23
- [Qemu-devel] [PATCH 16/21] test-qobject-input-visitor: Use strict visitor, Markus Armbruster, 2017/02/23
- [Qemu-devel] [PATCH 07/21] qmp: Eliminate silly QERR_QMP_* macros, Markus Armbruster, 2017/02/23
- [Qemu-devel] [PATCH 06/21] qmp: Drop duplicated QMP command object checks, Markus Armbruster, 2017/02/23