1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
From: Tobias Stoeckmann <tobias@stoeckmann.org>
Date: Fri, 12 Sep 2025 17:06:06 +0200
Subject: gutils: Support test env in load_user_special_dirs
XDG_CONFIG_DIR and HOME can be overridden with test environments. Read
these variables before building them again.
It's not possible to call the getter functions directly because the
caller of load_user_special_dirs already holds a lock and locking again
is undefined behavior and could lead to deadlocks.
Separate the functionality out into unlocked functions which definitely
have to be static to not expose them. Use them while holding the lock.
Origin: upstream, 2.86.1, commit:82c83a88712fb6e8ff16e228a6806137058b508b
---
glib/gutils.c | 28 +++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/glib/gutils.c b/glib/gutils.c
index 9c0fbdf..8f5d41b 100644
--- a/glib/gutils.c
+++ b/glib/gutils.c
@@ -899,6 +899,12 @@ g_build_home_dir (void)
return g_steal_pointer (&home_dir);
}
+static const gchar *
+g_get_home_dir_unlocked (void)
+{
+ return g_home_dir == NULL ? g_build_home_dir () : g_home_dir;
+}
+
/**
* g_get_home_dir:
*
@@ -932,9 +938,7 @@ g_get_home_dir (void)
G_LOCK (g_utils_global);
- if (g_home_dir == NULL)
- g_home_dir = g_build_home_dir ();
- home_dir = g_home_dir;
+ home_dir = g_get_home_dir_unlocked ();
G_UNLOCK (g_utils_global);
@@ -1953,6 +1957,12 @@ g_build_user_config_dir (void)
return g_steal_pointer (&config_dir);
}
+static const char *
+g_get_user_config_dir_unlocked (void)
+{
+ return g_user_config_dir == NULL ? g_build_user_config_dir () : g_user_config_dir;
+}
+
/**
* g_get_user_config_dir:
*
@@ -1985,9 +1995,7 @@ g_get_user_config_dir (void)
G_LOCK (g_utils_global);
- if (g_user_config_dir == NULL)
- g_user_config_dir = g_build_user_config_dir ();
- user_config_dir = g_user_config_dir;
+ user_config_dir = g_get_user_config_dir_unlocked ();
G_UNLOCK (g_utils_global);
@@ -2260,17 +2268,16 @@ load_user_special_dirs (void)
static void
load_user_special_dirs (void)
{
- gchar *config_dir = NULL;
+ const gchar *config_dir = NULL;
gchar *config_file;
gchar *data;
gchar **lines;
gint n_lines, i;
- config_dir = g_build_user_config_dir ();
+ config_dir = g_get_user_config_dir_unlocked ();
config_file = g_build_filename (config_dir,
"user-dirs.dirs",
NULL);
- g_free (config_dir);
if (!g_file_get_contents (config_file, &data, NULL, NULL))
{
@@ -2378,9 +2385,8 @@ load_user_special_dirs (void)
if (is_relative)
{
- gchar *home_dir = g_build_home_dir ();
+ const gchar *home_dir = g_get_home_dir_unlocked ();
g_user_special_dirs[directory] = g_build_filename (home_dir, d, NULL);
- g_free (home_dir);
}
else
g_user_special_dirs[directory] = g_strdup (d);
|