Signed-off-by: Benoit Canet <ben...@irqsave.net> --- monitor-system.c | 43 +++++++++++++++++++++++++++++++++++++++++++ monitor.c | 44 -------------------------------------------- 2 files changed, 43 insertions(+), 44 deletions(-)
diff --git a/monitor-system.c b/monitor-system.c index 51ca21f..90758db 100644 --- a/monitor-system.c +++ b/monitor-system.c @@ -67,3 +67,46 @@ int GCC_FMT_ATTR(2, 3) monitor_fprintf(FILE *stream, return 0; } +static void monitor_data_destroy(Monitor *mon) +{ + QDECREF(mon->outbuf); + qemu_mutex_destroy(&mon->out_lock); +} + +char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index, + int64_t cpu_index, Error **errp) +{ + char *output = NULL; + Monitor *old_mon, hmp; + + monitor_data_init(&hmp); + hmp.skip_flush = true; + + old_mon = cur_mon; + cur_mon = &hmp; + + if (has_cpu_index) { + int ret = monitor_set_cpu(cpu_index); + if (ret < 0) { + cur_mon = old_mon; + error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index", + "a CPU number"); + goto out; + } + } + + handle_user_command(&hmp, command_line); + cur_mon = old_mon; + + qemu_mutex_lock(&hmp.out_lock); + if (qstring_get_length(hmp.outbuf) > 0) { + output = g_strdup(qstring_get_str(hmp.outbuf)); + } else { + output = g_strdup(""); + } + qemu_mutex_unlock(&hmp.out_lock); + +out: + monitor_data_destroy(&hmp); + return output; +} diff --git a/monitor.c b/monitor.c index a31d1d0..30d8eda 100644 --- a/monitor.c +++ b/monitor.c @@ -551,50 +551,6 @@ void monitor_data_init(Monitor *mon) mon->cmd_table = mon_cmds; } -static void monitor_data_destroy(Monitor *mon) -{ - QDECREF(mon->outbuf); - qemu_mutex_destroy(&mon->out_lock); -} - -char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index, - int64_t cpu_index, Error **errp) -{ - char *output = NULL; - Monitor *old_mon, hmp; - - monitor_data_init(&hmp); - hmp.skip_flush = true; - - old_mon = cur_mon; - cur_mon = &hmp; - - if (has_cpu_index) { - int ret = monitor_set_cpu(cpu_index); - if (ret < 0) { - cur_mon = old_mon; - error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index", - "a CPU number"); - goto out; - } - } - - handle_user_command(&hmp, command_line); - cur_mon = old_mon; - - qemu_mutex_lock(&hmp.out_lock); - if (qstring_get_length(hmp.outbuf) > 0) { - output = g_strdup(qstring_get_str(hmp.outbuf)); - } else { - output = g_strdup(""); - } - qemu_mutex_unlock(&hmp.out_lock); - -out: - monitor_data_destroy(&hmp); - return output; -} - int compare_cmd(const char *name, const char *list) { const char *p, *pstart; -- 2.0.1