aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorGonglei <arei.gonglei@huawei.com>2015-02-05 17:43:34 +0800
committerGerd Hoffmann <kraxel@redhat.com>2015-02-16 08:47:59 +0100
commit2779672fa3f0680e63ecfd3ee2d6ff360ce948a2 (patch)
tree713bf0dacc489043e0c780bb7d22fb7372b2d8ee /ui
parenta2c72de09619ed4d2f4498a65027114f9c035f7f (diff)
vnc: introduce an wrapper for auto assign vnc id
Signed-off-by: Gonglei <arei.gonglei@huawei.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'ui')
-rw-r--r--ui/vnc.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/ui/vnc.c b/ui/vnc.c
index e7c35aa6b6..faa218f84b 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);