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>
This commit is contained in:
parent
a2c72de096
commit
2779672fa3
@ -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);
|
||||
|
22
ui/vnc.c
22
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);
|
||||
|
Loading…
Reference in New Issue
Block a user