From f9decb21f59cd28d572fbbf2b2ea2172adf556a0 Mon Sep 17 00:00:00 2001 From: Luiz Capitulino Date: Mon, 29 Mar 2010 16:14:56 -0300 Subject: [PATCH 21/23] Monitor: Audit handler return RH-Author: Luiz Capitulino Message-id: <1269879298-30711-22-git-send-email-lcapitulino@redhat.com> Patchwork-id: 8183 O-Subject: [PATCH 21/23] Monitor: Audit handler return Bugzilla: 563491 RH-Acked-by: Markus Armbruster RH-Acked-by: Juan Quintela RH-Acked-by: Kevin Wolf This commit verifies the following two rules specified by Markus Armbruster: 1. If the handler returns failure, it must have passed an error. If it didn't, it's broken. Report an internal error to the client, and report the bug to the programmer. 2. If the handler returns success, it must not have passed an error. If it did, it's broken. Report the error to the client, and report the bug to the programmer. Signed-off-by: Luiz Capitulino Signed-off-by: Anthony Liguori (cherry picked from commit bb89c2e901b1a0c1cb6b94392cae1f98e6660ed7) --- monitor.c | 32 +++++++++++++++++++++++++++++++- 1 files changed, 31 insertions(+), 1 deletions(-) Signed-off-by: Eduardo Habkost --- monitor.c | 32 +++++++++++++++++++++++++++++++- 1 files changed, 31 insertions(+), 1 deletions(-) diff --git a/monitor.c b/monitor.c index 4e0c8ea..059c49c 100644 --- a/monitor.c +++ b/monitor.c @@ -3888,12 +3888,42 @@ static int is_async_return(const QObject *data) return 0; } +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)) { + qemu_error_new(QERR_UNDEFINED_ERROR); + } + 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); + } +#endif +} + static void monitor_call_handler(Monitor *mon, const mon_cmd_t *cmd, const QDict *params) { + int ret; QObject *data = NULL; - cmd->mhandler.cmd_new(mon, params, &data); + ret = cmd->mhandler.cmd_new(mon, params, &data); + handler_audit(mon, cmd, ret); if (is_async_return(data)) { /* -- 1.7.0.3