aboutsummaryrefslogtreecommitdiff
path: root/monitor.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2010-03-02 14:56:34 +0100
committerMarkus Armbruster <armbru@redhat.com>2010-03-16 17:01:08 +0100
commitcde0fc7544ca590c83f349d4dcccf375d55d6042 (patch)
tree1b31f269b788b772394fd00a077eeae5fc9ea74f /monitor.c
parent6620d3ce9ee44c01c7d715322be7879ad3d98c7a (diff)
downloadqemu-cde0fc7544ca590c83f349d4dcccf375d55d6042.zip
qemu-cde0fc7544ca590c83f349d4dcccf375d55d6042.tar.gz
qemu-cde0fc7544ca590c83f349d4dcccf375d55d6042.tar.bz2
error: Let converted handlers print in human monitor
While fully converted handlers are not supposed to print anything when running in a QMP monitor, they are free to print in a human monitor. For instance, device_add (not yet converted) prints help, and will continue to do so after conversion. Moreover, utility functions converted to QError should remain usable from unconverted handlers. Two problems: * handler_audit() complains when a converted handler prints. Limit that to QMP monitors. * With QMP, handlers need to pass the error object by way of monitor_set_error(). However, we do that both for QMP and for the human monitor. The human monitor prints the error object after the handler returns. If the handler prints anything else, that output "overtakes" the error message. Limit use of monitor_set_error() to QMP monitors. Update handler_audit() accordingly.
Diffstat (limited to 'monitor.c')
-rw-r--r--monitor.c80
1 files changed, 37 insertions, 43 deletions
diff --git a/monitor.c b/monitor.c
index d8a3124..76c909c 100644
--- a/monitor.c
+++ b/monitor.c
@@ -3876,13 +3876,6 @@ void monitor_set_error(Monitor *mon, QError *qerror)
}
}
-static void monitor_print_error(Monitor *mon)
-{
- qerror_print(mon->error);
- QDECREF(mon->error);
- mon->error = NULL;
-}
-
static int is_async_return(const QObject *data)
{
if (data && qobject_type(data) == QTYPE_QDICT) {
@@ -3894,45 +3887,49 @@ static int is_async_return(const QObject *data)
static void handler_audit(Monitor *mon, const mon_cmd_t *cmd, int ret)
{
- if (ret && !monitor_has_error(mon)) {
- /*
- * If it returns failure, it must have passed on error.
- *
- * Action: Report an internal error to the client if in QMP.
- */
- if (monitor_ctrl_mode(mon)) {
+ if (monitor_ctrl_mode(mon)) {
+ if (ret && !monitor_has_error(mon)) {
+ /*
+ * If it returns failure, it must have passed on error.
+ *
+ * Action: Report an internal error to the client if in QMP.
+ */
qerror_report(QERR_UNDEFINED_ERROR);
+ MON_DEBUG("command '%s' returned failure but did not pass an error\n",
+ cmd->name);
}
- MON_DEBUG("command '%s' returned failure but did not pass an error\n",
- cmd->name);
- }
#ifdef CONFIG_DEBUG_MONITOR
- if (!ret && monitor_has_error(mon)) {
- /*
- * If it returns success, it must not have passed an error.
- *
- * Action: Report the passed error to the client.
- */
- MON_DEBUG("command '%s' returned success but passed an error\n",
- cmd->name);
- }
+ if (!ret && monitor_has_error(mon)) {
+ /*
+ * If it returns success, it must not have passed an error.
+ *
+ * Action: Report the passed error to the client.
+ */
+ MON_DEBUG("command '%s' returned success but passed an error\n",
+ cmd->name);
+ }
- if (mon_print_count_get(mon) > 0 && strcmp(cmd->name, "info") != 0) {
- /*
- * Handlers should not call Monitor print functions.
- *
- * Action: Ignore them in QMP.
- *
- * (XXX: we don't check any 'info' or 'query' command here
- * because the user print function _is_ called by do_info(), hence
- * we will trigger this check. This problem will go away when we
- * make 'query' commands real and kill do_info())
- */
- MON_DEBUG("command '%s' called print functions %d time(s)\n",
- cmd->name, mon_print_count_get(mon));
- }
+ if (mon_print_count_get(mon) > 0 && strcmp(cmd->name, "info") != 0) {
+ /*
+ * Handlers should not call Monitor print functions.
+ *
+ * Action: Ignore them in QMP.
+ *
+ * (XXX: we don't check any 'info' or 'query' command here
+ * because the user print function _is_ called by do_info(), hence
+ * we will trigger this check. This problem will go away when we
+ * make 'query' commands real and kill do_info())
+ */
+ MON_DEBUG("command '%s' called print functions %d time(s)\n",
+ cmd->name, mon_print_count_get(mon));
+ }
#endif
+ } else {
+ assert(!monitor_has_error(mon));
+ QDECREF(mon->error);
+ mon->error = NULL;
+ }
}
static void monitor_call_handler(Monitor *mon, const mon_cmd_t *cmd,
@@ -3985,9 +3982,6 @@ static void handle_user_command(Monitor *mon, const char *cmdline)
cmd->mhandler.cmd(mon, qdict);
}
- if (monitor_has_error(mon))
- monitor_print_error(mon);
-
out:
QDECREF(qdict);
}