From patchwork Thu Feb 5 09:36:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gonglei (Arei)" X-Patchwork-Id: 436720 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 80CED140216 for ; Thu, 5 Feb 2015 20:37:34 +1100 (AEDT) Received: from localhost ([::1]:40874 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJIsO-00021Y-Bg for incoming@patchwork.ozlabs.org; Thu, 05 Feb 2015 04:37:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37546) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJIrP-0000Rz-Aj for qemu-devel@nongnu.org; Thu, 05 Feb 2015 04:36:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YJIrL-0002te-I3 for qemu-devel@nongnu.org; Thu, 05 Feb 2015 04:36:31 -0500 Received: from szxga02-in.huawei.com ([119.145.14.65]:22677) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJIrK-0002t1-Ts for qemu-devel@nongnu.org; Thu, 05 Feb 2015 04:36:27 -0500 Received: from 172.24.2.119 (EHLO szxeml430-hub.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CGV95625; Thu, 05 Feb 2015 17:36:23 +0800 (CST) Received: from localhost (10.177.19.102) by szxeml430-hub.china.huawei.com (10.82.67.185) with Microsoft SMTP Server id 14.3.158.1; Thu, 5 Feb 2015 17:36:13 +0800 From: To: Date: Thu, 5 Feb 2015 17:36:08 +0800 Message-ID: <1423128969-5012-2-git-send-email-arei.gonglei@huawei.com> X-Mailer: git-send-email 1.7.3.1.msysgit.0 In-Reply-To: <1423128969-5012-1-git-send-email-arei.gonglei@huawei.com> References: <1423128969-5012-1-git-send-email-arei.gonglei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.19.102] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.65 Cc: Gonglei , kraxel@redhat.com, peter.huangpeng@huawei.com Subject: [Qemu-devel] [PATCH 1/2] vnc: introduce an wrapper for auto assign vnc id X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Gonglei Signed-off-by: Gonglei --- 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 4bae970..1a4117c 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3689,6 +3689,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; @@ -3697,13 +3710,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);