diff mbox

[09/11] Monitor: Introduce find_info_cmd()

Message ID 1264108180-3666-10-git-send-email-lcapitulino@redhat.com
State New
Headers show

Commit Message

Luiz Capitulino Jan. 21, 2010, 9:09 p.m. UTC
Move the code used to locate an info command entry to its
own function, as it's going to be used by other functions.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 monitor.c |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)
diff mbox

Patch

diff --git a/monitor.c b/monitor.c
index 321bc3a..34df1cc 100644
--- a/monitor.c
+++ b/monitor.c
@@ -512,6 +512,19 @@  static void do_async_msg_disable(Monitor *mon, const QDict *qdict,
     qevent_set_value(mon, qdict, 0);
 }
 
+static const mon_cmd_t *monitor_find_info_command(const char *name)
+{
+    const mon_cmd_t *cmd;
+
+    for (cmd = info_cmds; cmd->name != NULL; cmd++) {
+        if (compare_cmd(name, cmd->name)) {
+            return cmd;
+        }
+    }
+
+    return NULL;
+}
+
 static void do_info(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
     const mon_cmd_t *cmd;
@@ -522,12 +535,8 @@  static void do_info(Monitor *mon, const QDict *qdict, QObject **ret_data)
         goto help;
     }
 
-    for (cmd = info_cmds; cmd->name != NULL; cmd++) {
-        if (compare_cmd(item, cmd->name))
-            break;
-    }
-
-    if (cmd->name == NULL) {
+    cmd = monitor_find_info_command(item);
+    if (!cmd) {
         if (monitor_ctrl_mode(mon)) {
             qemu_error_new(QERR_COMMAND_NOT_FOUND, item);
             return;