From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:60189) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TBlaW-000883-Mk for qemu-devel@nongnu.org; Wed, 12 Sep 2012 07:58:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TBlaQ-0007Ln-Hv for qemu-devel@nongnu.org; Wed, 12 Sep 2012 07:58:36 -0400 Received: from e28smtp01.in.ibm.com ([122.248.162.1]:49811) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TBlaP-0007LK-V0 for qemu-devel@nongnu.org; Wed, 12 Sep 2012 07:58:30 -0400 Received: from /spool/local by e28smtp01.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 12 Sep 2012 17:28:27 +0530 Received: from d28av05.in.ibm.com (d28av05.in.ibm.com [9.184.220.67]) by d28relay03.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q8CBwOQa40501374 for ; Wed, 12 Sep 2012 17:28:24 +0530 Received: from d28av05.in.ibm.com (loopback [127.0.0.1]) by d28av05.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q8CBwNGg008765 for ; Wed, 12 Sep 2012 21:58:24 +1000 From: Lei Li Date: Wed, 12 Sep 2012 19:57:26 +0800 Message-Id: <1347451046-5513-6-git-send-email-lilei@linux.vnet.ibm.com> In-Reply-To: <1347451046-5513-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1347451046-5513-1-git-send-email-lilei@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 5/5] HMP: Introduce console command List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com, Lei Li , eblake@redhat.com, armbru@redhat.com, lcapitulino@redhat.com Signed-off-by: Lei Li --- hmp.c | 42 ++++++++++++++++++++++++++++++++++++++++++ monitor.c | 18 ++++++++++++++++++ monitor.h | 2 ++ 3 files changed, 62 insertions(+), 0 deletions(-) diff --git a/hmp.c b/hmp.c index 4397981..a016a5c 100644 --- a/hmp.c +++ b/hmp.c @@ -1205,3 +1205,45 @@ void hmp_screen_dump(Monitor *mon, const QDict *qdict) qmp_screendump(filename, &err); hmp_handle_error(mon, &err); } + +int console_escape_char = 0x1d; /* ctrl-] is used for escape */ + +static void hmp_read_console(Monitor *mon, const char *data, + void *opaque) +{ + CharDriverState *chr = opaque; + uint32_t size = strlen(data); + enum DataFormat format = DATA_FORMAT_UTF8; + enum CongestionControl control = CONGESTION_CONTROL_DROP; + + Error *err = NULL; + + if (*data == console_escape_char) { + monitor_resume(mon); + return; + } + + qmp_memchar_write(chr->label, size, data, 0, format, + 0, control, &err); + monitor_read_command(mon, 1); +} + +void hmp_console(Monitor *mon, const QDict *qdict) +{ + const char *device = qdict_get_str(qdict, "chardev"); + CharDriverState *chr; + Error *err = NULL; + + chr = qemu_chr_find(device); + + if (!chr) { + error_set(&err, QERR_DEVICE_NOT_FOUND, device); + hmp_handle_error(mon, &err); + return; + } + + if (monitor_read_console(mon, device, hmp_read_console, chr) < 0) { + monitor_printf(mon, "Connect to console %s failed\n", device); + } + g_free(chr); +} diff --git a/monitor.c b/monitor.c index 67064e2..285dc7b 100644 --- a/monitor.c +++ b/monitor.c @@ -256,6 +256,24 @@ int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func, } } +int monitor_read_console(Monitor *mon, const char *device, + ReadLineFunc *readline_func, void *opaque) +{ + char prompt[60]; + + if (!mon->rs) + return -1; + + if (monitor_ctrl_mode(mon)) { + qerror_report(QERR_MISSING_PARAMETER, "console"); + return -EINVAL; + } + + snprintf(prompt, sizeof(prompt), "%s: ", device); + readline_start(mon->rs, prompt, 0, readline_func, opaque); + return 0; +} + void monitor_flush(Monitor *mon) { if (mon && mon->outbuf_index != 0 && !mon->mux_out) { diff --git a/monitor.h b/monitor.h index 64c1561..924a042 100644 --- a/monitor.h +++ b/monitor.h @@ -84,6 +84,8 @@ void monitor_read_command(Monitor *mon, int show_prompt); ReadLineState *monitor_get_rs(Monitor *mon); int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func, void *opaque); +int monitor_read_console(Monitor *mon, const char *device, + ReadLineFunc *readline_func, void *opaque); int qmp_qom_set(Monitor *mon, const QDict *qdict, QObject **ret); -- 1.7.7.6