mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-23 12:41:50 +01:00
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
This commit is contained in:
parent
10f2d10f1c
commit
4b3183435b
@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
#include "gportalsupport.h"
|
#include "gportalsupport.h"
|
||||||
|
|
||||||
static gboolean flatpak_info_read;
|
|
||||||
static gboolean use_portal;
|
static gboolean use_portal;
|
||||||
static gboolean network_available;
|
static gboolean network_available;
|
||||||
static gboolean dconf_access;
|
static gboolean dconf_access;
|
||||||
@ -28,13 +27,12 @@ static gboolean dconf_access;
|
|||||||
static void
|
static void
|
||||||
read_flatpak_info (void)
|
read_flatpak_info (void)
|
||||||
{
|
{
|
||||||
|
static gsize flatpak_info_read = 0;
|
||||||
const gchar *path = "/.flatpak-info";
|
const gchar *path = "/.flatpak-info";
|
||||||
|
|
||||||
if (flatpak_info_read)
|
if (!g_once_init_enter (&flatpak_info_read))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
flatpak_info_read = TRUE;
|
|
||||||
|
|
||||||
if (g_file_test (path, G_FILE_TEST_EXISTS))
|
if (g_file_test (path, G_FILE_TEST_EXISTS))
|
||||||
{
|
{
|
||||||
GKeyFile *keyfile;
|
GKeyFile *keyfile;
|
||||||
@ -77,6 +75,8 @@ read_flatpak_info (void)
|
|||||||
network_available = TRUE;
|
network_available = TRUE;
|
||||||
dconf_access = TRUE;
|
dconf_access = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_once_init_leave (&flatpak_info_read, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
Loading…
Reference in New Issue
Block a user