mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
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.
This commit is contained in:
parent
898a9c332e
commit
ab278c0072
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user