Blame SOURCES/evolution-data-server-3.28.5-delay-new-module-load.patch

1a4a70
diff -up evolution-data-server-3.28.5/src/libebackend/e-dbus-server.c.delay-new-module-load evolution-data-server-3.28.5/src/libebackend/e-dbus-server.c
1a4a70
--- evolution-data-server-3.28.5/src/libebackend/e-dbus-server.c.delay-new-module-load	2018-07-30 15:17:06.000000000 +0200
1a4a70
+++ evolution-data-server-3.28.5/src/libebackend/e-dbus-server.c	2020-01-15 13:29:46.090644022 +0100
1a4a70
@@ -75,6 +75,78 @@ G_DEFINE_ABSTRACT_TYPE_WITH_CODE (
1a4a70
 	EDBusServer, e_dbus_server, G_TYPE_OBJECT,
1a4a70
 	G_IMPLEMENT_INTERFACE (E_TYPE_EXTENSIBLE, NULL))
1a4a70
 
1a4a70
+typedef struct _ModuleLoadData {
1a4a70
+	GWeakRef server_wr;
1a4a70
+	gchar *filename;
1a4a70
+} ModuleLoadData;
1a4a70
+
1a4a70
+static ModuleLoadData *
1a4a70
+module_load_data_new (EDBusServer *server,
1a4a70
+		      const gchar *filename)
1a4a70
+{
1a4a70
+	ModuleLoadData *mld;
1a4a70
+
1a4a70
+	mld = g_slice_new0 (ModuleLoadData);
1a4a70
+	g_weak_ref_init (&mld->server_wr, server);
1a4a70
+	mld->filename = g_strdup (filename);
1a4a70
+
1a4a70
+	return mld;
1a4a70
+}
1a4a70
+
1a4a70
+static void
1a4a70
+module_load_data_free (gpointer ptr)
1a4a70
+{
1a4a70
+	ModuleLoadData *mld = ptr;
1a4a70
+
1a4a70
+	if (mld) {
1a4a70
+		g_weak_ref_clear (&mld->server_wr);
1a4a70
+		g_free (mld->filename);
1a4a70
+		g_slice_free (ModuleLoadData, mld);
1a4a70
+	}
1a4a70
+}
1a4a70
+
1a4a70
+static gboolean
1a4a70
+e_dbus_server_load_module_timeout_cb (gpointer user_data)
1a4a70
+{
1a4a70
+	ModuleLoadData *mld = user_data;
1a4a70
+	EDBusServer *server;
1a4a70
+
1a4a70
+	g_return_val_if_fail (mld != NULL, FALSE);
1a4a70
+
1a4a70
+	server = g_weak_ref_get (&mld->server_wr);
1a4a70
+	if (server) {
1a4a70
+		EModule *module;
1a4a70
+
1a4a70
+		e_source_registry_debug_print ("Loading module '%s'\n", mld->filename);
1a4a70
+
1a4a70
+		module = e_module_load_file (mld->filename);
1a4a70
+		if (module) {
1a4a70
+			g_type_module_unuse ((GTypeModule *) module);
1a4a70
+
1a4a70
+			e_dbus_server_quit (server, E_DBUS_SERVER_EXIT_RELOAD);
1a4a70
+		}
1a4a70
+
1a4a70
+		g_object_unref (server);
1a4a70
+	}
1a4a70
+
1a4a70
+	return FALSE;
1a4a70
+}
1a4a70
+
1a4a70
+static void
1a4a70
+e_dbus_server_schedule_module_load (EDBusServer *server,
1a4a70
+				    const gchar *filename)
1a4a70
+{
1a4a70
+	g_return_if_fail (E_IS_DBUS_SERVER (server));
1a4a70
+	g_return_if_fail (filename != NULL);
1a4a70
+
1a4a70
+	e_source_registry_debug_print ("Schedule load of module '%s'\n", filename);
1a4a70
+
1a4a70
+	/* Delay the load by 10 seconds, in case the module doesn't have placed
1a4a70
+	   all its libraries in the expected directories. */
1a4a70
+	g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, 10, e_dbus_server_load_module_timeout_cb,
1a4a70
+		module_load_data_new (server, filename), module_load_data_free);
1a4a70
+}
1a4a70
+
1a4a70
 static void
1a4a70
 dbus_server_bus_acquired_cb (GDBusConnection *connection,
1a4a70
                              const gchar *bus_name,
1a4a70
@@ -552,38 +624,27 @@ dbus_server_module_directory_changed_cb
1a4a70
 		if (event_type == G_FILE_MONITOR_EVENT_RENAMED && other_file) {
1a4a70
 			G_LOCK (loaded_modules);
1a4a70
 			if (!g_hash_table_contains (loaded_modules, filename)) {
1a4a70
+				gchar *other_filename = g_file_get_path (other_file);
1a4a70
+				e_source_registry_debug_print ("Module file '%s' renamed to '%s'\n", filename, other_filename);
1a4a70
 				g_free (filename);
1a4a70
-				filename = g_file_get_path (other_file);
1a4a70
+				filename = other_filename;
1a4a70
 				event_type = G_FILE_MONITOR_EVENT_CREATED;
1a4a70
 			}
1a4a70
 			G_UNLOCK (loaded_modules);
1a4a70
 		}
1a4a70
 
1a4a70
 		if (filename && g_str_has_suffix (filename, "." G_MODULE_SUFFIX)) {
1a4a70
-			gboolean any_loaded = FALSE;
1a4a70
-
1a4a70
 			if (event_type == G_FILE_MONITOR_EVENT_CREATED ||
1a4a70
 			    event_type == G_FILE_MONITOR_EVENT_MOVED_IN) {
1a4a70
 				G_LOCK (loaded_modules);
1a4a70
 
1a4a70
 				if (!g_hash_table_contains (loaded_modules, filename)) {
1a4a70
-					EModule *module;
1a4a70
-
1a4a70
 					g_hash_table_add (loaded_modules, g_strdup (filename));
1a4a70
-
1a4a70
-					module = e_module_load_file (filename);
1a4a70
-					if (module) {
1a4a70
-						any_loaded = TRUE;
1a4a70
-
1a4a70
-						g_type_module_unuse ((GTypeModule *) module);
1a4a70
-					}
1a4a70
+					e_dbus_server_schedule_module_load (server, filename);
1a4a70
 				}
1a4a70
 
1a4a70
 				G_UNLOCK (loaded_modules);
1a4a70
 			}
1a4a70
-
1a4a70
-			if (any_loaded)
1a4a70
-				e_dbus_server_quit (server, E_DBUS_SERVER_EXIT_RELOAD);
1a4a70
 		}
1a4a70
 
1a4a70
 		g_free (filename);