From 46574fcc54eba3ed4245f85d2725c6ea019b39be Mon Sep 17 00:00:00 2001 From: Ting-Wei Lan Date: Fri, 22 Dec 2017 21:45:38 +0800 Subject: Replace all hard-coded /etc path with sysconfdir 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 --- bin/dconf-update.vala | 5 ++++- engine/dconf-engine-profile.c | 4 ++-- engine/dconf-engine-source-system.c | 2 +- meson.build | 3 ++- tests/engine.c | 36 ++++++++++++++++++------------------ 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 #include -/* 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")); -- cgit v1.2.1