1 From ea2bd3a49ab04110cde4e71d9afafcf5d93db909 Mon Sep 17 00:00:00 2001
2 From: Alexandre Derumier <aderumier@odiso.com>
3 Date: Mon, 8 Apr 2013 12:42:48 +0200
4 Subject: [PATCH 1/2] Add spice support for unix socket option
7 Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
9 qemu-options.hx | 5 ++++-
10 ui/spice-core.c | 22 +++++++++++++++++++---
11 2 files changed, 23 insertions(+), 4 deletions(-)
13 diff --git a/qemu-options.hx b/qemu-options.hx
14 index 06b6e58..37d271a 100644
17 @@ -887,7 +887,7 @@ Enable SDL.
20 DEF("spice", HAS_ARG, QEMU_OPTION_spice,
21 - "-spice [port=port][,tls-port=secured-port][,x509-dir=<dir>]\n"
22 + "-spice [port=port][,tls-port=secured-port][,unix=<sock>][,x509-dir=<dir>]\n"
23 " [,x509-key-file=<file>][,x509-key-password=<file>]\n"
24 " [,x509-cert-file=<file>][,x509-cacert-file=<file>]\n"
25 " [,x509-dh-key-file=<file>][,addr=addr][,ipv4|ipv6]\n"
26 @@ -911,6 +911,9 @@ Enable the spice remote desktop protocol. Valid options are
31 +Path on which to bind a UNIX socket.
34 Set the TCP port spice is listening on for plaintext channels.
36 diff --git a/ui/spice-core.c b/ui/spice-core.c
37 index bcc4199..acc1626 100644
42 #include "ui/spice-display.h"
44 +static const int on=1, off=0;
48 static SpiceServer *spice_server;
49 @@ -428,6 +430,9 @@ static QemuOptsList qemu_spice_opts = {
51 .type = QEMU_OPT_NUMBER,
54 + .type = QEMU_OPT_STRING,
57 .type = QEMU_OPT_STRING,
59 @@ -640,16 +645,18 @@ void qemu_spice_init(void)
60 spice_image_compression_t compression;
61 spice_wan_compression_t wan_compr;
62 bool seamless_migration;
63 + const char *unix_socket;
65 qemu_thread_get_self(&me);
70 + unix_socket = qemu_opt_get(opts, "unix");
71 port = qemu_opt_get_number(opts, "port", 0);
72 tls_port = qemu_opt_get_number(opts, "tls-port", 0);
73 - if (!port && !tls_port) {
74 - error_report("neither port nor tls-port specified for spice");
75 + if (!port && !tls_port && !unix_socket) {
76 + error_report("neither sock, port nor tls-port specified for spice");
79 if (port < 0 || port > 65535) {
80 @@ -705,7 +712,6 @@ void qemu_spice_init(void)
81 } else if (qemu_opt_get_bool(opts, "ipv6", 0)) {
82 addr_flags |= SPICE_ADDR_FLAG_IPV6_ONLY;
85 spice_server = spice_server_new();
86 spice_server_set_addr(spice_server, addr ? addr : "", addr_flags);
88 @@ -720,6 +726,16 @@ void qemu_spice_init(void)
95 + dpy = g_malloc(256);
96 + pstrcpy(dpy, 256, unix_socket);
97 + Error *local_err = NULL;
98 + lsock = unix_listen(unix_socket, dpy, 256, &local_err);
99 + setsockopt(lsock, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on));
100 + spice_server_set_listen_socket_fd(spice_server, lsock);
103 spice_server_set_ticket(spice_server, password, 0, 0, 0);