diff options
author | Markus Armbruster <armbru@redhat.com> | 2018-07-03 10:53:44 +0200 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2018-07-03 23:18:56 +0200 |
commit | 1cc37471525d03f963bc71d724f0dc9eab888fc1 (patch) | |
tree | ae68bea009963f6bf9c39b97a16adddcdc698103 /monitor.c | |
parent | 69240fe62d1ae02257bc0694a11c478b10378948 (diff) |
qmp: Don't let JSON errors jump the queue
handle_qmp_command() reports JSON syntax errors right away. This is
wrong when OOB is enabled, because the errors can "jump the queue"
then.
The previous commit fixed the same bug for semantic errors, by
delaying the checking until dispatch. We can't delay the checking, so
delay the reporting.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180703085358.13941-19-armbru@redhat.com>
Diffstat (limited to 'monitor.c')
-rw-r--r-- | monitor.c | 23 |
1 files changed, 15 insertions, 8 deletions
@@ -254,8 +254,12 @@ struct QMPRequest { Monitor *mon; /* "id" field of the request */ QObject *id; - /* Request object to be handled */ + /* + * Request object to be handled or Error to be reported + * (exactly one of them is non-null) + */ QObject *req; + Error *err; /* * Whether we need to resume the monitor afterward. This flag is * used to emulate the old QMP server behavior that the current @@ -360,6 +364,7 @@ static void qmp_request_free(QMPRequest *req) { qobject_unref(req->id); qobject_unref(req->req); + error_free(req->err); g_free(req); } @@ -4199,8 +4204,14 @@ static void monitor_qmp_bh_dispatcher(void *data) return; } - trace_monitor_qmp_cmd_in_band(qobject_get_try_str(req_obj->id) ?: ""); - monitor_qmp_dispatch(req_obj->mon, req_obj->req, req_obj->id); + if (req_obj->req) { + trace_monitor_qmp_cmd_in_band(qobject_get_try_str(req_obj->id) ?: ""); + monitor_qmp_dispatch(req_obj->mon, req_obj->req, req_obj->id); + } else { + assert(req_obj->err); + monitor_qmp_respond(req_obj->mon, NULL, req_obj->err, NULL); + } + if (req_obj->need_resume) { /* Pairs with the monitor_suspend() in handle_qmp_command() */ monitor_resume(req_obj->mon); @@ -4227,11 +4238,6 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens) /* json_parser_parse_err() sucks: can fail without setting @err */ error_setg(&err, QERR_JSON_PARSING); } - if (err) { - assert(!req); - monitor_qmp_respond(mon, NULL, err, NULL); - return; - } qdict = qobject_to(QDict, req); if (qdict) { @@ -4257,6 +4263,7 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens) req_obj->mon = mon; req_obj->id = id; req_obj->req = req; + req_obj->err = err; req_obj->need_resume = false; /* Protect qmp_requests and fetching its length. */ |