Blame SOURCES/0001-vdagentd-work-around-GLib-s-fork-issues.patch

fed39a
From 51489290e7fbd771907751990eda719199ff491e Mon Sep 17 00:00:00 2001
fed39a
From: =?UTF-8?q?Jakub=20Jank=C5=AF?= <jjanku@redhat.com>
fed39a
Date: Fri, 20 Mar 2020 10:36:03 +0100
fed39a
Subject: [PATCH 1/4] vdagentd: work around GLib's fork issues
fed39a
MIME-Version: 1.0
fed39a
Content-Type: text/plain; charset=UTF-8
fed39a
Content-Transfer-Encoding: 8bit
fed39a
fed39a
Creating threads is not compatible with forking as only the thread
fed39a
that calls fork() is inherited.
fed39a
fed39a
Handlers registered with g_unix_signal_add() create a thread so
fed39a
move these calls after fork.
fed39a
fed39a
Also call g_socket_service_start() after fork to avoid creation of
fed39a
new threads before it is necessary.
fed39a
fed39a
Fixes: https://gitlab.freedesktop.org/spice/linux/vd_agent/issues/18
fed39a
fed39a
Also see: https://gitlab.gnome.org/GNOME/glib/issues/2073
fed39a
fed39a
Signed-off-by: Jakub Janků <jjanku@redhat.com>
fed39a
Acked-by: Frediano Ziglio <fziglio@redhat.com>
fed39a
(cherry picked from commit 9b8c0ebb9fb573e6ce3c5416371509f416503d0c)
fed39a
---
fed39a
 src/udscs.c             | 6 ++++++
fed39a
 src/udscs.h             | 2 ++
fed39a
 src/vdagentd/vdagentd.c | 9 +++++----
fed39a
 3 files changed, 13 insertions(+), 4 deletions(-)
fed39a
fed39a
diff --git a/src/udscs.c b/src/udscs.c
fed39a
index 4de75f8..7c99eed 100644
fed39a
--- a/src/udscs.c
fed39a
+++ b/src/udscs.c
fed39a
@@ -186,6 +186,7 @@ struct udscs_server *udscs_server_new(
fed39a
     server->read_callback = read_callback;
fed39a
     server->error_cb = error_cb;
fed39a
     server->service = g_socket_service_new();
fed39a
+    g_socket_service_stop(server->service);
fed39a
 
fed39a
     g_signal_connect(server->service, "incoming",
fed39a
         G_CALLBACK(udscs_server_accept_cb), server);
fed39a
@@ -223,6 +224,11 @@ void udscs_server_listen_to_address(struct udscs_server *server,
fed39a
     g_object_unref(sock_addr);
fed39a
 }
fed39a
 
fed39a
+void udscs_server_start(struct udscs_server *server)
fed39a
+{
fed39a
+    g_socket_service_start(server->service);
fed39a
+}
fed39a
+
fed39a
 void udscs_server_destroy_connection(struct udscs_server *server,
fed39a
                                      UdscsConnection     *conn)
fed39a
 {
fed39a
diff --git a/src/udscs.h b/src/udscs.h
fed39a
index 45ebd3f..4f7ea36 100644
fed39a
--- a/src/udscs.h
fed39a
+++ b/src/udscs.h
fed39a
@@ -98,6 +98,8 @@ void udscs_server_listen_to_address(struct udscs_server *server,
fed39a
                                     const gchar         *addr,
fed39a
                                     GError             **err);
fed39a
 
fed39a
+void udscs_server_start(struct udscs_server *server);
fed39a
+
fed39a
 void udscs_server_destroy_connection(struct udscs_server *server,
fed39a
                                      UdscsConnection     *conn);
fed39a
 
fed39a
diff --git a/src/vdagentd/vdagentd.c b/src/vdagentd/vdagentd.c
fed39a
index cfd0a51..1b63ec8 100644
fed39a
--- a/src/vdagentd/vdagentd.c
fed39a
+++ b/src/vdagentd/vdagentd.c
fed39a
@@ -1184,10 +1184,6 @@ int main(int argc, char *argv[])
fed39a
         uinput_device = g_strdup(DEFAULT_UINPUT_DEVICE);
fed39a
     }
fed39a
 
fed39a
-    g_unix_signal_add(SIGINT, signal_handler, NULL);
fed39a
-    g_unix_signal_add(SIGHUP, signal_handler, NULL);
fed39a
-    g_unix_signal_add(SIGTERM, signal_handler, NULL);
fed39a
-
fed39a
     openlog("spice-vdagentd", do_daemonize ? 0 : LOG_PERROR, LOG_USER);
fed39a
 
fed39a
     /* Setup communication with vdagent process(es) */
fed39a
@@ -1240,6 +1236,10 @@ int main(int argc, char *argv[])
fed39a
     }
fed39a
 #endif
fed39a
 
fed39a
+    g_unix_signal_add(SIGINT, signal_handler, NULL);
fed39a
+    g_unix_signal_add(SIGHUP, signal_handler, NULL);
fed39a
+    g_unix_signal_add(SIGTERM, signal_handler, NULL);
fed39a
+
fed39a
     if (want_session_info)
fed39a
         session_info = session_info_create(debug);
fed39a
     if (session_info) {
fed39a
@@ -1252,6 +1252,7 @@ int main(int argc, char *argv[])
fed39a
 
fed39a
     active_xfers = g_hash_table_new(g_direct_hash, g_direct_equal);
fed39a
 
fed39a
+    udscs_server_start(server);
fed39a
     loop = g_main_loop_new(NULL, FALSE);
fed39a
     g_main_loop_run(loop);
fed39a
 
fed39a
-- 
fed39a
2.26.1
fed39a