From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47934) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNH1A-0003nz-Bk for qemu-devel@nongnu.org; Mon, 16 Feb 2015 03:27:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YNH14-0008OJ-6X for qemu-devel@nongnu.org; Mon, 16 Feb 2015 03:27:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50371) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNH13-0008O7-V7 for qemu-devel@nongnu.org; Mon, 16 Feb 2015 03:26:54 -0500 From: Gerd Hoffmann Date: Mon, 16 Feb 2015 09:26:02 +0100 Message-Id: <1424075165-25016-5-git-send-email-kraxel@redhat.com> In-Reply-To: <1424075165-25016-1-git-send-email-kraxel@redhat.com> References: <1424075165-25016-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PULL 4/7] vnc: introduce an wrapper for auto assign vnc id List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gonglei , Gerd Hoffmann , Anthony Liguori From: Gonglei Signed-off-by: Gonglei Signed-off-by: Gerd Hoffmann --- include/ui/console.h | 1 + ui/vnc.c | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index 8a4d671..5c19c3c 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -335,6 +335,7 @@ void vnc_display_init(const char *id); void vnc_display_open(const char *id, Error **errp); void vnc_display_add_client(const char *id, int csock, bool skipauth); char *vnc_display_local_addr(const char *id); +void vnc_auto_assign_id(QemuOptsList *olist, QemuOpts *opts); #ifdef CONFIG_VNC int vnc_display_password(const char *id, const char *password); int vnc_display_pw_expire(const char *id, time_t expires); diff --git a/ui/vnc.c b/ui/vnc.c index e7c35aa..faa218f 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3685,6 +3685,19 @@ QemuOpts *vnc_parse_func(const char *str) return qemu_opts_parse(qemu_find_opts("vnc"), str, 1); } +void vnc_auto_assign_id(QemuOptsList *olist, QemuOpts *opts) +{ + int i = 2; + char *id; + + id = g_strdup("default"); + while (qemu_opts_find(olist, id)) { + g_free(id); + id = g_strdup_printf("vnc%d", i++); + } + qemu_opts_set_id(opts, id); +} + int vnc_init_func(QemuOpts *opts, void *opaque) { Error *local_err = NULL; @@ -3693,13 +3706,8 @@ int vnc_init_func(QemuOpts *opts, void *opaque) if (!id) { /* auto-assign id if not present */ - int i = 2; - id = g_strdup("default"); - while (qemu_opts_find(olist, id)) { - g_free(id); - id = g_strdup_printf("vnc%d", i++); - } - qemu_opts_set_id(opts, id); + vnc_auto_assign_id(olist, opts); + id = (char *)qemu_opts_id(opts); } vnc_display_init(id); -- 1.8.3.1