[spice-vdagent] Make the per session agent process automatically reconnect to the system spice-vdagentd when the sys
Hans de Goede
jwrdegoede at fedoraproject.org
Fri Jul 15 10:10:30 UTC 2011
commit 6ccc7717290f38769254ba11d7cdb243474ba645
Author: Hans de Goede <hdegoede at redhat.com>
Date: Fri Jul 15 12:11:41 2011 +0200
Make the per session agent process automatically reconnect to the system
spice-vdagentd when the system daemon gets restarted
...reconnect-to-system-socket-every-second-w.patch | 93 ++++++++++++++++++++
0002-vdagents-add-VDAGENTD_VERSION-message.patch | 84 ++++++++++++++++++
...ck-for-portdev-existence-and-leave-if-not.patch | 85 ++++++++++++++++++
...dagent-reexec-ourself-on-version-mismatch.patch | 73 +++++++++++++++
0005-vdagent-Fix-double-free-on-re-exec.patch | 47 ++++++++++
...pond-to-SIGTERM-in-the-connect-to-daemon-.patch | 31 +++++++
spice-vdagent.spec | 18 ++++-
7 files changed, 430 insertions(+), 1 deletions(-)
---
diff --git a/0001-Attempt-to-reconnect-to-system-socket-every-second-w.patch b/0001-Attempt-to-reconnect-to-system-socket-every-second-w.patch
new file mode 100644
index 0000000..1d571f0
--- /dev/null
+++ b/0001-Attempt-to-reconnect-to-system-socket-every-second-w.patch
@@ -0,0 +1,93 @@
+From 5814222821a5e41e610633b73d6e739be7c4cbad Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau at redhat.com>
+Date: Fri, 20 May 2011 03:03:05 +0200
+Subject: [linux-vdagent PATCH 1/4] Attempt to reconnect to system socket
+ every second when daemonized
+
+https://bugzilla.redhat.com/show_bug.cgi?id=681797
+---
+ src/udscs.c | 6 ++++--
+ src/vdagent.c | 31 +++++++++++++++++++++----------
+ 2 files changed, 25 insertions(+), 12 deletions(-)
+
+diff --git a/src/udscs.c b/src/udscs.c
+index c451855..6f1328e 100644
+--- a/src/udscs.c
++++ b/src/udscs.c
+@@ -182,8 +182,10 @@ struct udscs_connection *udscs_connect(const char *socketname,
+ snprintf(address.sun_path, sizeof(address.sun_path), "%s", socketname);
+ c = connect(conn->fd, (struct sockaddr *)&address, sizeof(address));
+ if (c != 0) {
+- fprintf(conn->errfile, "connect %s: %s\n", socketname,
+- strerror(errno));
++ if (conn->logfile) {
++ fprintf(conn->logfile, "connect %s: %s\n", socketname,
++ strerror(errno));
++ }
+ free(conn);
+ return NULL;
+ }
+diff --git a/src/vdagent.c b/src/vdagent.c
+index 3569cdb..2b69865 100644
+--- a/src/vdagent.c
++++ b/src/vdagent.c
+@@ -76,6 +76,20 @@ void daemon_read_complete(struct udscs_connection **connp,
+ }
+ }
+
++int client_setup(int reconnect)
++{
++ while (1) {
++ client = udscs_connect(VDAGENTD_SOCKET, daemon_read_complete, NULL,
++ vdagentd_messages, VDAGENTD_NO_MESSAGES,
++ verbose ? logfile : NULL, logfile);
++ if (client || !reconnect) {
++ break;
++ }
++ sleep(1);
++ }
++ return client == NULL;
++}
++
+ static void usage(FILE *fp)
+ {
+ fprintf(fp,
+@@ -168,21 +182,16 @@ int main(int argc, char *argv[])
+ if (do_daemonize)
+ daemonize();
+
+- client = udscs_connect(VDAGENTD_SOCKET, daemon_read_complete, NULL,
+- vdagentd_messages, VDAGENTD_NO_MESSAGES,
+- verbose? logfile:NULL, logfile);
+- if (!client) {
+- if (logfile != stderr)
+- fclose(logfile);
+- return 1;
++ if (client_setup(do_daemonize)) {
++ retval = 1;
++ goto finish;
+ }
+
+ x11 = vdagent_x11_create(client, logfile, verbose);
+ if (!x11) {
+ udscs_destroy_connection(&client);
+- if (logfile != stderr)
+- fclose(logfile);
+- return 1;
++ retval = 1;
++ goto finish;
+ }
+
+ while (client && !quit) {
+@@ -212,6 +221,8 @@ int main(int argc, char *argv[])
+
+ vdagent_x11_destroy(x11);
+ udscs_destroy_connection(&client);
++
++finish:
+ if (logfile != stderr)
+ fclose(logfile);
+
+--
+1.7.5.1
+
diff --git a/0002-vdagents-add-VDAGENTD_VERSION-message.patch b/0002-vdagents-add-VDAGENTD_VERSION-message.patch
new file mode 100644
index 0000000..63e8806
--- /dev/null
+++ b/0002-vdagents-add-VDAGENTD_VERSION-message.patch
@@ -0,0 +1,84 @@
+From a65884e6b6894c56492771b0a1bbb8458941a991 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau at redhat.com>
+Date: Thu, 16 Jun 2011 13:10:55 +0200
+Subject: [linux-vdagent PATCH 2/4] vdagents: add VDAGENTD_VERSION message
+
+Disconnects vdagent if version mismatch.
+---
+ src/vdagent.c | 12 ++++++++++++
+ src/vdagentd-proto-strings.h | 1 +
+ src/vdagentd-proto.h | 1 +
+ src/vdagentd.c | 3 +++
+ 4 files changed, 17 insertions(+), 0 deletions(-)
+
+diff --git a/src/vdagent.c b/src/vdagent.c
+index 2b69865..db18617 100644
+--- a/src/vdagent.c
++++ b/src/vdagent.c
+@@ -19,6 +19,10 @@
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
++#ifdef HAVE_CONFIG_H
++# include <config.h>
++#endif
++
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+@@ -68,6 +72,14 @@ void daemon_read_complete(struct udscs_connection **connp,
+ vdagent_x11_clipboard_release(x11, header->arg1);
+ free(data);
+ break;
++ case VDAGENTD_VERSION:
++ if (strcmp(data, VERSION) != 0) {
++ fprintf(logfile,
++ "Fatal vdagentd version mismatch: got %s expected %s\n",
++ data, VERSION);
++ udscs_destroy_connection(connp);
++ }
++ break;
+ default:
+ if (verbose)
+ fprintf(logfile, "Unknown message from vdagentd type: %d\n",
+diff --git a/src/vdagentd-proto-strings.h b/src/vdagentd-proto-strings.h
+index 02adf01..f39e25b 100644
+--- a/src/vdagentd-proto-strings.h
++++ b/src/vdagentd-proto-strings.h
+@@ -29,6 +29,7 @@ static const char * const vdagentd_messages[] = {
+ "clipboard request",
+ "clipboard data",
+ "clipboard release",
++ "version",
+ };
+
+ #endif
+diff --git a/src/vdagentd-proto.h b/src/vdagentd-proto.h
+index e570d2b..9d96540 100644
+--- a/src/vdagentd-proto.h
++++ b/src/vdagentd-proto.h
+@@ -33,6 +33,7 @@ enum {
+ VDAGENTD_CLIPBOARD_REQUEST, /* arg1: selection, arg 2 = type */
+ VDAGENTD_CLIPBOARD_DATA, /* arg1: sel, arg 2: type, data: data */
+ VDAGENTD_CLIPBOARD_RELEASE, /* arg1: selection */
++ VDAGENTD_VERSION, /* daemon -> client, data: version string */
+ VDAGENTD_NO_MESSAGES /* Must always be last */
+ };
+
+diff --git a/src/vdagentd.c b/src/vdagentd.c
+index be6ef1f..3c05ef0 100644
+--- a/src/vdagentd.c
++++ b/src/vdagentd.c
+@@ -522,6 +522,9 @@ void agent_connect(struct udscs_connection *conn)
+ udscs_set_user_data(conn, (void *)agent_data);
+ update_active_session_connection();
+
++ udscs_write(conn, VDAGENTD_VERSION, 0, 0,
++ (uint8_t *)VERSION, strlen(VERSION) + 1);
++
+ if (mon_config)
+ udscs_write(conn, VDAGENTD_MONITORS_CONFIG, 0, 0,
+ (uint8_t *)mon_config, sizeof(VDAgentMonitorsConfig) +
+--
+1.7.5.1
+
diff --git a/0003-vdagent-check-for-portdev-existence-and-leave-if-not.patch b/0003-vdagent-check-for-portdev-existence-and-leave-if-not.patch
new file mode 100644
index 0000000..984c53c
--- /dev/null
+++ b/0003-vdagent-check-for-portdev-existence-and-leave-if-not.patch
@@ -0,0 +1,85 @@
+From b5f8b3c39df91767391832d0b6f0b12a880c2b0d Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau at redhat.com>
+Date: Thu, 16 Jun 2011 12:39:38 +0200
+Subject: [linux-vdagent PATCH 3/4] vdagent: check for portdev existence and
+ leave if not
+
+---
+ src/vdagent.c | 28 ++++++++++++++++++++++++----
+ 1 files changed, 24 insertions(+), 4 deletions(-)
+
+diff --git a/src/vdagent.c b/src/vdagent.c
+index db18617..c40cf5f 100644
+--- a/src/vdagent.c
++++ b/src/vdagent.c
+@@ -39,6 +39,7 @@
+ #include "vdagentd-proto-strings.h"
+ #include "vdagent-x11.h"
+
++static const char *portdev = "/dev/virtio-ports/com.redhat.spice.0";
+ static int verbose = 0;
+ static struct vdagent_x11 *x11 = NULL;
+ static struct udscs_connection *client = NULL;
+@@ -107,9 +108,11 @@ static void usage(FILE *fp)
+ fprintf(fp,
+ "vdagent -- spice agent xorg client\n"
+ "options:\n"
+- " -h print this text\n"
+- " -d log debug messages\n"
+- " -x don't daemonize (and log to logfile)\n");
++ " -h print this text\n"
++ " -d log debug messages\n"
++ " -s <port> set virtio serial port [%s]\n"
++ " -x don't daemonize (and log to logfile)\n",
++ portdev);
+ }
+
+ static void quit_handler(int sig)
+@@ -138,6 +141,13 @@ void daemonize(void)
+ }
+ }
+
++static int file_test(const char *path)
++{
++ struct stat buffer;
++
++ return stat(path, &buffer);
++}
++
+ int main(int argc, char *argv[])
+ {
+ fd_set readfds, writefds;
+@@ -147,12 +157,15 @@ int main(int argc, char *argv[])
+ struct sigaction act;
+
+ for (;;) {
+- if (-1 == (c = getopt(argc, argv, "-dxh")))
++ if (-1 == (c = getopt(argc, argv, "-dxhs:")))
+ break;
+ switch (c) {
+ case 'd':
+ verbose++;
+ break;
++ case 's':
++ portdev = optarg;
++ break;
+ case 'x':
+ do_daemonize = 0;
+ break;
+@@ -191,6 +204,13 @@ int main(int argc, char *argv[])
+ fprintf(stderr, "Could not get home directory, logging to stderr\n");
+ }
+
++ if (file_test(portdev) != 0) {
++ fprintf(logfile, "Missing virtio device: %s\n",
++ portdev, strerror(errno));
++ retval = 1;
++ goto finish;
++ }
++
+ if (do_daemonize)
+ daemonize();
+
+--
+1.7.5.1
+
diff --git a/0004-vdagent-reexec-ourself-on-version-mismatch.patch b/0004-vdagent-reexec-ourself-on-version-mismatch.patch
new file mode 100644
index 0000000..fc0bc4c
--- /dev/null
+++ b/0004-vdagent-reexec-ourself-on-version-mismatch.patch
@@ -0,0 +1,73 @@
+From 39b256e9f11c5cc7115a214654fda8891bfb473f Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau at redhat.com>
+Date: Thu, 16 Jun 2011 13:34:47 +0200
+Subject: [linux-vdagent PATCH 4/4] vdagent: reexec ourself on version
+ mismatch
+
+---
+ src/vdagent.c | 21 +++++++++++++++++++++
+ 1 files changed, 21 insertions(+), 0 deletions(-)
+
+diff --git a/src/vdagent.c b/src/vdagent.c
+index c40cf5f..5bf0452 100644
+--- a/src/vdagent.c
++++ b/src/vdagent.c
+@@ -45,6 +45,7 @@ static struct vdagent_x11 *x11 = NULL;
+ static struct udscs_connection *client = NULL;
+ static FILE *logfile = NULL;
+ static int quit = 0;
++static int version_mismatch = 0;
+
+ void daemon_read_complete(struct udscs_connection **connp,
+ struct udscs_message_header *header, uint8_t *data)
+@@ -79,6 +80,7 @@ void daemon_read_complete(struct udscs_connection **connp,
+ "Fatal vdagentd version mismatch: got %s expected %s\n",
+ data, VERSION);
+ udscs_destroy_connection(connp);
++ version_mismatch = 1;
+ }
+ break;
+ default:
+@@ -148,6 +150,15 @@ static int file_test(const char *path)
+ return stat(path, &buffer);
+ }
+
++static void cleanup(void)
++{
++ vdagent_x11_destroy(x11);
++ udscs_destroy_connection(&client);
++
++ if (logfile != stderr)
++ fclose(logfile);
++}
++
+ int main(int argc, char *argv[])
+ {
+ fd_set readfds, writefds;
+@@ -214,6 +225,14 @@ int main(int argc, char *argv[])
+ if (do_daemonize)
+ daemonize();
+
++reconnect:
++ if (version_mismatch) {
++ fprintf(logfile, "Version mismatch, restarting\n");
++ cleanup();
++ sleep(1);
++ execvp(argv[0], argv);
++ }
++
+ if (client_setup(do_daemonize)) {
+ retval = 1;
+ goto finish;
+@@ -253,6 +272,8 @@ int main(int argc, char *argv[])
+
+ vdagent_x11_destroy(x11);
+ udscs_destroy_connection(&client);
++ if (!quit)
++ goto reconnect;
+
+ finish:
+ if (logfile != stderr)
+--
+1.7.5.1
+
diff --git a/0005-vdagent-Fix-double-free-on-re-exec.patch b/0005-vdagent-Fix-double-free-on-re-exec.patch
new file mode 100644
index 0000000..84ff146
--- /dev/null
+++ b/0005-vdagent-Fix-double-free-on-re-exec.patch
@@ -0,0 +1,47 @@
+From e1c0ba33dff4f937b9c0f8f5bae42f2787691654 Mon Sep 17 00:00:00 2001
+From: Hans de Goede <hdegoede at redhat.com>
+Date: Fri, 15 Jul 2011 11:40:46 +0200
+Subject: [linux-vdagent PATCH] vdagent: Fix double free on re-exec
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+This is caused by me fixing a memleak in the non re-exec reconnect patch
+of Marc-André's original patch before merging it.
+---
+ src/vdagent.c | 12 ++----------
+ 1 files changed, 2 insertions(+), 10 deletions(-)
+
+diff --git a/src/vdagent.c b/src/vdagent.c
+index 5bf0452..5371ca2 100644
+--- a/src/vdagent.c
++++ b/src/vdagent.c
+@@ -150,15 +150,6 @@ static int file_test(const char *path)
+ return stat(path, &buffer);
+ }
+
+-static void cleanup(void)
+-{
+- vdagent_x11_destroy(x11);
+- udscs_destroy_connection(&client);
+-
+- if (logfile != stderr)
+- fclose(logfile);
+-}
+-
+ int main(int argc, char *argv[])
+ {
+ fd_set readfds, writefds;
+@@ -228,7 +219,8 @@ int main(int argc, char *argv[])
+ reconnect:
+ if (version_mismatch) {
+ fprintf(logfile, "Version mismatch, restarting\n");
+- cleanup();
++ if (logfile != stderr)
++ fclose(logfile);
+ sleep(1);
+ execvp(argv[0], argv);
+ }
+--
+1.7.5.1
+
diff --git a/0006-vdagent-Respond-to-SIGTERM-in-the-connect-to-daemon-.patch b/0006-vdagent-Respond-to-SIGTERM-in-the-connect-to-daemon-.patch
new file mode 100644
index 0000000..d6e247a
--- /dev/null
+++ b/0006-vdagent-Respond-to-SIGTERM-in-the-connect-to-daemon-.patch
@@ -0,0 +1,31 @@
+From 56fc8d0cc19dae7170fb515e5264c7db7df5773f Mon Sep 17 00:00:00 2001
+From: Hans de Goede <hdegoede at redhat.com>
+Date: Fri, 15 Jul 2011 11:52:42 +0200
+Subject: [linux-vdagent PATCH] vdagent: Respond to SIGTERM in the connect to
+ daemon loop
+
+---
+ src/vdagent.c | 4 ++--
+ 1 files changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/src/vdagent.c b/src/vdagent.c
+index 5371ca2..f0d3b32 100644
+--- a/src/vdagent.c
++++ b/src/vdagent.c
+@@ -93,11 +93,11 @@ void daemon_read_complete(struct udscs_connection **connp,
+
+ int client_setup(int reconnect)
+ {
+- while (1) {
++ while (!quit) {
+ client = udscs_connect(VDAGENTD_SOCKET, daemon_read_complete, NULL,
+ vdagentd_messages, VDAGENTD_NO_MESSAGES,
+ verbose ? logfile : NULL, logfile);
+- if (client || !reconnect) {
++ if (client || !reconnect || quit) {
+ break;
+ }
+ sleep(1);
+--
+1.7.5.1
+
diff --git a/spice-vdagent.spec b/spice-vdagent.spec
index cba471b..d35aa08 100644
--- a/spice-vdagent.spec
+++ b/spice-vdagent.spec
@@ -1,11 +1,17 @@
Name: spice-vdagent
Version: 0.8.0
-Release: 1%{?dist}
+Release: 2%{?dist}
Summary: Agent for Spice guests
Group: Applications/System
License: GPLv3+
URL: http://spice-space.org/
Source0: http://spice-space.org/download/releases/%{name}-%{version}.tar.bz2
+Patch1: 0001-Attempt-to-reconnect-to-system-socket-every-second-w.patch
+Patch2: 0002-vdagents-add-VDAGENTD_VERSION-message.patch
+Patch3: 0003-vdagent-check-for-portdev-existence-and-leave-if-not.patch
+Patch4: 0004-vdagent-reexec-ourself-on-version-mismatch.patch
+Patch5: 0005-vdagent-Fix-double-free-on-re-exec.patch
+Patch6: 0006-vdagent-Respond-to-SIGTERM-in-the-connect-to-daemon-.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: dbus-devel spice-protocol libXrandr-devel libXfixes-devel
BuildRequires: desktop-file-utils
@@ -30,6 +36,12 @@ Features:
%prep
%setup -q
+%patch1 -p1
+%patch2 -p1
+%patch3 -p1
+%patch4 -p1
+%patch5 -p1
+%patch6 -p1
%build
@@ -77,6 +89,10 @@ fi
%changelog
+* Fri Jul 15 2011 Hans de Goede <hdegoede at redhat.com> 0.8.0-2
+- Make the per session agent process automatically reconnect to the system
+ spice-vdagentd when the system daemon gets restarted
+
* Tue Apr 19 2011 Hans de Goede <hdegoede at redhat.com> 0.8.0-1
- New upstream release 0.8.0
More information about the scm-commits
mailing list