From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41114) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJ7kH-0001xv-8Z for qemu-devel@nongnu.org; Mon, 09 Sep 2013 16:07:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VJ7kB-0004E5-93 for qemu-devel@nongnu.org; Mon, 09 Sep 2013 16:07:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45073) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJ7kA-0004Cu-VV for qemu-devel@nongnu.org; Mon, 09 Sep 2013 16:07:31 -0400 Date: Mon, 9 Sep 2013 15:13:31 -0400 From: Luiz Capitulino Message-ID: <20130909151331.4341483e@redhat.com> In-Reply-To: <1378112508-8970-2-git-send-email-lilei@linux.vnet.ibm.com> References: <1378112508-8970-1-git-send-email-lilei@linux.vnet.ibm.com> <1378112508-8970-2-git-send-email-lilei@linux.vnet.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/4] monitor: introduce monitor_read_console List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Lei Li Cc: qemu-devel@nongnu.org, anthony@codemonkey.ws On Mon, 2 Sep 2013 17:01:45 +0800 Lei Li wrote: > This patch introduces monitor_read_console(), which will drop > into interactive mode with chardev ringbuf backend, and install > a readline handler. When the handler is invoked, the given data > will be written to ringbuf backend. > > Signed-off-by: Lei Li > --- > include/monitor/monitor.h | 3 +++ > monitor.c | 14 ++++++++++++++ > 2 files changed, 17 insertions(+), 0 deletions(-) > > diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h > index 1942cc4..e6a6f47 100644 > --- a/include/monitor/monitor.h > +++ b/include/monitor/monitor.h > @@ -89,6 +89,9 @@ 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); > > int qmp_qom_get(Monitor *mon, const QDict *qdict, QObject **ret); > diff --git a/monitor.c b/monitor.c > index 0aeaf6c..531095e 100644 > --- a/monitor.c > +++ b/monitor.c > @@ -263,6 +263,20 @@ 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; > + } > + > + snprintf(prompt, sizeof(prompt), "%s: ", device); You can use g_strdup_printf() to avoid a fixed size buffer. > + readline_start(mon->rs, prompt, 0, readline_func, opaque); > + return 0; > +} > + > static gboolean monitor_unblocked(GIOChannel *chan, GIOCondition cond, > void *opaque) > {