From ab278c0072f8e690ca4e7c3143a979dcc06e0a44 Mon Sep 17 00:00:00 2001 From: Ondrej Holy Date: Mon, 17 Feb 2020 11:05:07 +0100 Subject: [PATCH] gunixmounts: Prevent race when mtab file changed mtab_file_changed_id might be set on thread default context, but it is always cleared on the global context because of usage of g_idle_add. This can cause the emission of redundant "mounts-change" signals. This should not cause any issues to the client application, but let's attach the idle source to the thread-default context instead to avoid those races for sure. --- gio/gunixmounts.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/gio/gunixmounts.c b/gio/gunixmounts.c index 8b12d8fbc..1f7077c11 100644 --- a/gio/gunixmounts.c +++ b/gio/gunixmounts.c @@ -1756,6 +1756,9 @@ mtab_file_changed (GFileMonitor *monitor, GFileMonitorEvent event_type, gpointer user_data) { + GMainContext *context; + GSource *source; + if (event_type != G_FILE_MONITOR_EVENT_CHANGED && event_type != G_FILE_MONITOR_EVENT_CREATED && event_type != G_FILE_MONITOR_EVENT_DELETED) @@ -1768,7 +1771,16 @@ mtab_file_changed (GFileMonitor *monitor, if (mtab_file_changed_id > 0) return; - mtab_file_changed_id = g_idle_add (mtab_file_changed_cb, NULL); + context = g_main_context_get_thread_default (); + if (!context) + context = g_main_context_default (); + + source = g_idle_source_new (); + g_source_set_priority (source, G_PRIORITY_DEFAULT); + g_source_set_callback (source, mtab_file_changed_cb, NULL, NULL); + g_source_set_name (source, "[gio] mtab_file_changed_cb"); + g_source_attach (source, context); + g_source_unref (source); } static gboolean