summaryrefslogtreecommitdiff
path: root/pango/pango-utils.c
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2012-01-15 09:43:59 -0500
committerColin Walters <walters@verbum.org>2012-04-25 16:07:36 -0400
commitaecbe27c1b08f517c0e05f03308d3ac55cef490c (patch)
tree283377bcfc7cf1f504da8d4d9f2682a28a95c4ca /pango/pango-utils.c
parent04664794a8f239eb51e1bf537b42ea6f289336db (diff)
downloadpango-aecbe27c1b08f517c0e05f03308d3ac55cef490c.tar.gz
querymodules: Add --system argument
When run as a system trigger, we really don't want to be consulting e.g. /root/.pangorc. Also, the OSTree build system can run as non-root, but we don't in this case want to look at /home/user since the user may not even exist in the password database inside the chroot. https://bugzilla.gnome.org/show_bug.cgi?id=667960
Diffstat (limited to 'pango/pango-utils.c')
-rw-r--r--pango/pango-utils.c67
1 files changed, 53 insertions, 14 deletions
diff --git a/pango/pango-utils.c b/pango/pango-utils.c
index 44ec353d..8177dab2 100644
--- a/pango/pango-utils.c
+++ b/pango/pango-utils.c
@@ -532,6 +532,7 @@ pango_scan_int (const char **pos, int *out)
}
static GHashTable *config_hash = NULL;
+static gboolean did_read_user_config = FALSE;
static void
read_config_file (const char *filename, gboolean enoent_error)
@@ -604,23 +605,41 @@ read_config_file (const char *filename, gboolean enoent_error)
}
static void
-read_config (void)
+ensure_config_hash (void)
{
if (!config_hash)
- {
- char *filename;
- const char *home;
- const char *envvar;
-
- config_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
- (GDestroyNotify)g_free,
- (GDestroyNotify)g_free);
- filename = g_build_filename (pango_get_sysconf_subdirectory (),
- "pangorc",
- NULL);
- read_config_file (filename, FALSE);
- g_free (filename);
+ config_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
+ (GDestroyNotify)g_free,
+ (GDestroyNotify)g_free);
+}
+
+static void
+read_config_system (void)
+{
+ char *filename;
+
+ ensure_config_hash ();
+
+ filename = g_build_filename (pango_get_sysconf_subdirectory (),
+ "pangorc",
+ NULL);
+ read_config_file (filename, FALSE);
+ g_free (filename);
+}
+
+static void
+read_config (void)
+{
+ char *filename;
+ const char *home;
+ const char *envvar;
+ read_config_system ();
+
+ if (!did_read_user_config)
+ {
+ did_read_user_config = TRUE;
+
home = g_get_home_dir ();
if (home && *home)
{
@@ -636,6 +655,26 @@ read_config (void)
}
/**
+ * pango_config_key_get_system:
+ * @key: Key to look up, in the form "SECTION/KEY".
+ *
+ * Looks up a key, consulting only the Pango system config database
+ * in $sysconfdir/pango/pangorc.
+ *
+ * Return value: the value, if found, otherwise %NULL. The value is a
+ * newly-allocated string and must be freed with g_free().
+ **/
+char *
+pango_config_key_get_system (const char *key)
+{
+ g_return_val_if_fail (key != NULL, NULL);
+
+ read_config_system ();
+
+ return g_strdup (g_hash_table_lookup (config_hash, key));
+}
+
+/**
* pango_config_key_get:
* @key: Key to look up, in the form "SECTION/KEY".
*