[glib/wip/wjt/2159-thread-unsafe-initialization-in-gportalsupport-c] portal: Read /.flatpak-info in thread-safe fashion



commit 4b3183435bc14daca21bced6d51ac81493649c11
Author: Will Thompson <wjt endlessm com>
Date:   Mon Jul 13 16:26:44 2020 +0100

    portal: Read /.flatpak-info in thread-safe fashion
    
    There is no guarantee that this function would not be called
    concurrently. Particularly since flatpak_info_read was set to TRUE
    before /.flatpak-info is actually read from disk, there is a potential
    race where a second thread would return default values for the various
    flags set from that file.
    
    Fixes #2159

 gio/gportalsupport.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/gio/gportalsupport.c b/gio/gportalsupport.c
index b0a94b360..233f6af45 100644
--- a/gio/gportalsupport.c
+++ b/gio/gportalsupport.c
@@ -20,7 +20,6 @@
 
 #include "gportalsupport.h"
 
-static gboolean flatpak_info_read;
 static gboolean use_portal;
 static gboolean network_available;
 static gboolean dconf_access;
@@ -28,13 +27,12 @@ static gboolean dconf_access;
 static void
 read_flatpak_info (void)
 {
+  static gsize flatpak_info_read = 0;
   const gchar *path = "/.flatpak-info";
 
-  if (flatpak_info_read)
+  if (!g_once_init_enter (&flatpak_info_read))
     return;
 
-  flatpak_info_read = TRUE;
-
   if (g_file_test (path, G_FILE_TEST_EXISTS))
     {
       GKeyFile *keyfile;
@@ -77,6 +75,8 @@ read_flatpak_info (void)
       network_available = TRUE;
       dconf_access = TRUE;
     }
+
+  g_once_init_leave (&flatpak_info_read, 1);
 }
 
 gboolean


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]