summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTing-Wei Lan <lantw@src.gnome.org>2017-12-22 21:45:38 +0800
committerTing-Wei Lan <lantw@src.gnome.org>2018-08-16 23:11:46 +0800
commit46574fcc54eba3ed4245f85d2725c6ea019b39be (patch)
treebcb09da74e5967becd68d2971cf812c83b84961e
parenta28fd39f780bbd6098a4852696de1a432b1a61c1 (diff)
downloaddconf-wip/lantw/dont-hard-code-etc.tar.gz
Replace all hard-coded /etc path with sysconfdirwip/lantw/dont-hard-code-etc
This is useful for JHBuild environments and systems that don't want to use /etc/dconf. https://bugzilla.gnome.org/show_bug.cgi?id=739299
-rw-r--r--bin/dconf-update.vala5
-rw-r--r--engine/dconf-engine-profile.c4
-rw-r--r--engine/dconf-engine-source-system.c2
-rw-r--r--meson.build3
-rw-r--r--tests/engine.c36
5 files changed, 27 insertions, 23 deletions
diff --git a/bin/dconf-update.vala b/bin/dconf-update.vala
index b7a41dc..55a8231 100644
--- a/bin/dconf-update.vala
+++ b/bin/dconf-update.vala
@@ -247,8 +247,11 @@ void dconf_compile (string[] args) throws GLib.Error {
}
}
+[CCode (cname = "SYSCONFDIR")]
+extern const string CONFIG_SYSCONFDIR;
+
void dconf_update (string[] args) throws GLib.Error {
- update_all ("/etc/dconf/db");
+ update_all (CONFIG_SYSCONFDIR + "/dconf/db");
}
// vim:noet ts=4 sw=4
diff --git a/engine/dconf-engine-profile.c b/engine/dconf-engine-profile.c
index cc9f83f..b204bb4 100644
--- a/engine/dconf-engine-profile.c
+++ b/engine/dconf-engine-profile.c
@@ -189,12 +189,12 @@ static FILE *
dconf_engine_open_profile_file (const gchar *profile)
{
const gchar * const *xdg_data_dirs;
- const gchar *prefix = "/etc";
+ const gchar *prefix = SYSCONFDIR;
FILE *fp;
xdg_data_dirs = g_get_system_data_dirs ();
- /* First time through, we check "/etc", then we check XDG_DATA_DIRS,
+ /* First time through, we check SYSCONFDIR, then we check XDG_DATA_DIRS,
* in order. We stop looking as soon as we successfully open a file
* or in the case that we run out of XDG_DATA_DIRS.
*
diff --git a/engine/dconf-engine-source-system.c b/engine/dconf-engine-source-system.c
index d9e7de8..0d7c2d8 100644
--- a/engine/dconf-engine-source-system.c
+++ b/engine/dconf-engine-source-system.c
@@ -47,7 +47,7 @@ dconf_engine_source_system_reopen (DConfEngineSource *source)
GvdbTable *table;
gchar *filename;
- filename = g_build_filename ("/etc/dconf/db", source->name, NULL);
+ filename = g_build_filename (SYSCONFDIR "/dconf/db", source->name, NULL);
table = gvdb_table_new (filename, FALSE, &error);
if (table == NULL)
diff --git a/meson.build b/meson.build
index e441948..ba14507 100644
--- a/meson.build
+++ b/meson.build
@@ -10,6 +10,7 @@ dconf_datadir = join_paths(dconf_prefix, get_option('datadir'))
dconf_libdir = join_paths(dconf_prefix, get_option('libdir'))
dconf_libexecdir = join_paths(dconf_prefix, get_option('libexecdir'))
dconf_mandir = join_paths(dconf_prefix, get_option('mandir'))
+dconf_sysconfdir = join_paths(dconf_prefix, get_option('sysconfdir'))
dconf_namespace = 'ca.desrt.dconf'
@@ -22,7 +23,7 @@ cc = meson.get_compiler('c')
valac = meson.get_compiler('vala')
# compiler flags
-common_flags = []
+common_flags = ['-DSYSCONFDIR="@0@"'.format(dconf_sysconfdir)]
if get_option('buildtype').contains('debug')
common_flags += cc.get_supported_arguments([
diff --git a/tests/engine.c b/tests/engine.c
index f2e57b2..b351126 100644
--- a/tests/engine.c
+++ b/tests/engine.c
@@ -14,7 +14,7 @@
#include <dlfcn.h>
#include <math.h>
-/* Interpose to catch fopen("/etc/dconf/profile/user") */
+/* Interpose to catch fopen(SYSCONFDIR "/dconf/profile/user") */
static const gchar *filename_to_replace;
static const gchar *filename_to_replace_it_with;
@@ -116,7 +116,7 @@ test_five_times (const gchar *filename,
g_unsetenv ("DCONF_PROFILE");
/* next try supplying a profile name via API and intercepting fopen */
- filename_to_replace = "/etc/dconf/profile/myprofile";
+ filename_to_replace = SYSCONFDIR "/dconf/profile/myprofile";
filename_to_replace_it_with = filename;
g_assert (g_getenv ("DCONF_PROFILE") == NULL);
sources = dconf_engine_profile_open ("myprofile", &n_sources);
@@ -125,7 +125,7 @@ test_five_times (const gchar *filename,
/* next try the same, via the environment */
g_setenv ("DCONF_PROFILE", "myprofile", TRUE);
- filename_to_replace = "/etc/dconf/profile/myprofile";
+ filename_to_replace = SYSCONFDIR "/dconf/profile/myprofile";
filename_to_replace_it_with = filename;
sources = dconf_engine_profile_open (NULL, &n_sources);
verify_and_free (sources, n_sources, expected_names, n_expected);
@@ -133,7 +133,7 @@ test_five_times (const gchar *filename,
filename_to_replace = NULL;
/* next try to have dconf pick it up as the default user profile */
- filename_to_replace = "/etc/dconf/profile/user";
+ filename_to_replace = SYSCONFDIR "/dconf/profile/user";
filename_to_replace_it_with = filename;
g_assert (g_getenv ("DCONF_PROFILE") == NULL);
sources = dconf_engine_profile_open (NULL, &n_sources);
@@ -202,7 +202,7 @@ test_profile_parser (void)
/* finally, test that we get the default profile if the user profile
* file cannot be located and we do not specify another profile.
*/
- filename_to_replace = "/etc/dconf/profile/user";
+ filename_to_replace = SYSCONFDIR "/dconf/profile/user";
filename_to_replace_it_with = SRCDIR "/profile/this-file-does-not-exist";
g_assert (g_getenv ("DCONF_PROFILE") == NULL);
sources = dconf_engine_profile_open (NULL, &n_sources);
@@ -563,7 +563,7 @@ test_system_source (void)
/* Create the file after the fact and make sure it opens properly */
first_table = dconf_mock_gvdb_table_new ();
- dconf_mock_gvdb_install ("/etc/dconf/db/site", first_table);
+ dconf_mock_gvdb_install (SYSCONFDIR "/dconf/db/site", first_table);
reopened = dconf_engine_source_refresh (source);
g_assert (reopened);
@@ -580,7 +580,7 @@ test_system_source (void)
/* Create the file before the first refresh attempt */
first_table = dconf_mock_gvdb_table_new ();
- dconf_mock_gvdb_install ("/etc/dconf/db/site", first_table);
+ dconf_mock_gvdb_install (SYSCONFDIR "/dconf/db/site", first_table);
/* Hang on to a copy for ourselves for below... */
dconf_mock_gvdb_table_ref (first_table);
@@ -596,7 +596,7 @@ test_system_source (void)
/* Replace the table on "disk" but don't invalidate the old one */
next_table = dconf_mock_gvdb_table_new ();
- dconf_mock_gvdb_install ("/etc/dconf/db/site", next_table);
+ dconf_mock_gvdb_install (SYSCONFDIR "/dconf/db/site", next_table);
/* Make sure the old table remains open (ie: no IO performed) */
reopened = dconf_engine_source_refresh (source);
@@ -611,7 +611,7 @@ test_system_source (void)
g_assert (source->values == next_table);
/* Remove the file entirely and do the same thing */
- dconf_mock_gvdb_install ("/etc/dconf/db/site", NULL);
+ dconf_mock_gvdb_install (SYSCONFDIR "/dconf/db/site", NULL);
reopened = dconf_engine_source_refresh (source);
g_assert (!reopened);
@@ -688,7 +688,7 @@ setup_state (guint n_sources,
state[i] = NULL;
}
- filename = g_strdup_printf ("/etc/dconf/db/db%d", i);
+ filename = g_strdup_printf (SYSCONFDIR "/dconf/db/db%d", i);
}
else
{
@@ -933,7 +933,7 @@ is_expected (const gchar *log_domain,
{
return g_str_equal (log_domain, "dconf") &&
log_level == (G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL) &&
- strstr (message, "unable to open file '/etc/dconf/db");
+ strstr (message, "unable to open file '" SYSCONFDIR "/dconf/db");
}
static gboolean
@@ -1160,7 +1160,7 @@ test_watch_fast (void)
table = dconf_mock_gvdb_table_new ();
dconf_mock_gvdb_install ("/HOME/.config/dconf/user", table);
table = dconf_mock_gvdb_table_new ();
- dconf_mock_gvdb_install ("/etc/dconf/db/site", table);
+ dconf_mock_gvdb_install (SYSCONFDIR "/dconf/db/site", table);
triv = g_variant_ref_sink (g_variant_new ("()"));
@@ -1225,7 +1225,7 @@ test_watch_fast (void)
dconf_mock_dbus_assert_no_async ();
dconf_mock_gvdb_install ("/HOME/.config/dconf/user", NULL);
- dconf_mock_gvdb_install ("/etc/dconf/db/site", NULL);
+ dconf_mock_gvdb_install (SYSCONFDIR "/dconf/db/site", NULL);
dconf_engine_unref (engine);
g_string_free (change_log, TRUE);
change_log = NULL;
@@ -1248,7 +1248,7 @@ test_watch_fast_simultaneous_subscriptions (void)
table = dconf_mock_gvdb_table_new ();
dconf_mock_gvdb_install ("/HOME/.config/dconf/user", table);
table = dconf_mock_gvdb_table_new ();
- dconf_mock_gvdb_install ("/etc/dconf/db/site", table);
+ dconf_mock_gvdb_install (SYSCONFDIR "/dconf/db/site", table);
triv = g_variant_ref_sink (g_variant_new ("()"));
@@ -1311,7 +1311,7 @@ test_watch_fast_successive_subscriptions (void)
table = dconf_mock_gvdb_table_new ();
dconf_mock_gvdb_install ("/HOME/.config/dconf/user", table);
table = dconf_mock_gvdb_table_new ();
- dconf_mock_gvdb_install ("/etc/dconf/db/site", table);
+ dconf_mock_gvdb_install (SYSCONFDIR "/dconf/db/site", table);
triv = g_variant_ref_sink (g_variant_new ("()"));
@@ -1377,7 +1377,7 @@ test_watch_fast_short_lived_subscriptions (void)
table = dconf_mock_gvdb_table_new ();
dconf_mock_gvdb_install ("/HOME/.config/dconf/user", table);
table = dconf_mock_gvdb_table_new ();
- dconf_mock_gvdb_install ("/etc/dconf/db/site", table);
+ dconf_mock_gvdb_install (SYSCONFDIR "/dconf/db/site", table);
triv = g_variant_ref_sink (g_variant_new ("()"));
@@ -1508,7 +1508,7 @@ test_change_fast (void)
locks = dconf_mock_gvdb_table_new ();
dconf_mock_gvdb_table_insert (locks, "/locked", g_variant_new_boolean (TRUE), NULL);
dconf_mock_gvdb_table_insert (table, ".locks", NULL, locks);
- dconf_mock_gvdb_install ("/etc/dconf/db/site", table);
+ dconf_mock_gvdb_install (SYSCONFDIR "/dconf/db/site", table);
empty = dconf_changeset_new ();
good_write = dconf_changeset_new_write ("/value", g_variant_new_string ("value"));
@@ -1686,7 +1686,7 @@ test_change_sync (void)
locks = dconf_mock_gvdb_table_new ();
dconf_mock_gvdb_table_insert (locks, "/locked", g_variant_new_boolean (TRUE), NULL);
dconf_mock_gvdb_table_insert (table, ".locks", NULL, locks);
- dconf_mock_gvdb_install ("/etc/dconf/db/site", table);
+ dconf_mock_gvdb_install (SYSCONFDIR "/dconf/db/site", table);
empty = dconf_changeset_new ();
good_write = dconf_changeset_new_write ("/value", g_variant_new_string ("value"));