mirror of https://github.com/xemu-project/xemu.git
monitor: Limit QError use to command handlers
The previous commits narrowed use of QError to handle_qmp_command() and its helpers monitor_protocol_emitter(), build_qmp_error_dict(). Narrow it further to just the command handler call: instead of converting Error to QError throughout handle_qmp_command(), convert the QError gotten from the command handler to Error, and switch the helpers from QError to Error. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
This commit is contained in:
parent
452e0300a3
commit
710aec915d
27
monitor.c
27
monitor.c
|
@ -391,19 +391,19 @@ static void monitor_json_emitter(Monitor *mon, const QObject *data)
|
||||||
QDECREF(json);
|
QDECREF(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
static QDict *build_qmp_error_dict(const QError *err)
|
static QDict *build_qmp_error_dict(Error *err)
|
||||||
{
|
{
|
||||||
QObject *obj;
|
QObject *obj;
|
||||||
|
|
||||||
obj = qobject_from_jsonf("{ 'error': { 'class': %s, 'desc': %p } }",
|
obj = qobject_from_jsonf("{ 'error': { 'class': %s, 'desc': %s } }",
|
||||||
ErrorClass_lookup[err->err_class],
|
ErrorClass_lookup[error_get_class(err)],
|
||||||
qerror_human(err));
|
error_get_pretty(err));
|
||||||
|
|
||||||
return qobject_to_qdict(obj);
|
return qobject_to_qdict(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void monitor_protocol_emitter(Monitor *mon, QObject *data,
|
static void monitor_protocol_emitter(Monitor *mon, QObject *data,
|
||||||
QError *err)
|
Error *err)
|
||||||
{
|
{
|
||||||
QDict *qmp;
|
QDict *qmp;
|
||||||
|
|
||||||
|
@ -4983,13 +4983,12 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
|
||||||
obj = json_parser_parse(tokens, NULL);
|
obj = json_parser_parse(tokens, NULL);
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
// FIXME: should be triggered in json_parser_parse()
|
// FIXME: should be triggered in json_parser_parse()
|
||||||
qerror_report(QERR_JSON_PARSING);
|
error_set(&local_err, QERR_JSON_PARSING);
|
||||||
goto err_out;
|
goto err_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
input = qmp_check_input_obj(obj, &local_err);
|
input = qmp_check_input_obj(obj, &local_err);
|
||||||
if (!input) {
|
if (!input) {
|
||||||
qerror_report_err(local_err);
|
|
||||||
qobject_decref(obj);
|
qobject_decref(obj);
|
||||||
goto err_out;
|
goto err_out;
|
||||||
}
|
}
|
||||||
|
@ -5001,12 +5000,11 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
|
||||||
trace_handle_qmp_command(mon, cmd_name);
|
trace_handle_qmp_command(mon, cmd_name);
|
||||||
cmd = qmp_find_cmd(cmd_name);
|
cmd = qmp_find_cmd(cmd_name);
|
||||||
if (!cmd) {
|
if (!cmd) {
|
||||||
qerror_report(ERROR_CLASS_COMMAND_NOT_FOUND,
|
error_set(&local_err, ERROR_CLASS_COMMAND_NOT_FOUND,
|
||||||
"The command %s has not been found", cmd_name);
|
"The command %s has not been found", cmd_name);
|
||||||
goto err_out;
|
goto err_out;
|
||||||
}
|
}
|
||||||
if (invalid_qmp_mode(mon, cmd, &local_err)) {
|
if (invalid_qmp_mode(mon, cmd, &local_err)) {
|
||||||
qerror_report_err(local_err);
|
|
||||||
goto err_out;
|
goto err_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5020,7 +5018,6 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
|
||||||
|
|
||||||
qmp_check_client_args(cmd, args, &local_err);
|
qmp_check_client_args(cmd, args, &local_err);
|
||||||
if (local_err) {
|
if (local_err) {
|
||||||
qerror_report_err(local_err);
|
|
||||||
goto err_out;
|
goto err_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5028,12 +5025,16 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
|
||||||
/* Command failed... */
|
/* Command failed... */
|
||||||
if (!mon->error) {
|
if (!mon->error) {
|
||||||
/* ... without setting an error, so make one up */
|
/* ... without setting an error, so make one up */
|
||||||
qerror_report(QERR_UNDEFINED_ERROR);
|
error_set(&local_err, QERR_UNDEFINED_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (mon->error) {
|
||||||
|
error_set(&local_err, mon->error->err_class, "%s",
|
||||||
|
mon->error->err_msg);
|
||||||
|
}
|
||||||
|
|
||||||
err_out:
|
err_out:
|
||||||
monitor_protocol_emitter(mon, data, mon->error);
|
monitor_protocol_emitter(mon, data, local_err);
|
||||||
qobject_decref(data);
|
qobject_decref(data);
|
||||||
QDECREF(mon->error);
|
QDECREF(mon->error);
|
||||||
mon->error = NULL;
|
mon->error = NULL;
|
||||||
|
|
Loading…
Reference in New Issue