[gnome-initial-setup/mcatanzaro/vendor-conf] Create a search path for vendor.conf



commit b984b6b6aee914a5ad175f80f67c8ffbf8642c23
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Tue May 5 15:56:45 2020 -0500

    Create a search path for vendor.conf
    
    Now, if the build option is not specified, we'll first check /etc and
    then /usr/share. This allows OEMs to drop files in a location not
    managed by ostree, and allows distributions to have a default immutable
    config if not overridden by the OEM. If the build option is passed, the
    search path is disabled and the value from the build option used
    instead, so anyone currently using the build option won't notice any
    change (but also won't benefit from the addition of the search path).

 gnome-initial-setup/gis-driver.c | 45 ++++++++++++++++++++++++++++++++--------
 meson.build                      | 14 +++++++------
 meson_options.txt                |  2 +-
 3 files changed, 45 insertions(+), 16 deletions(-)
---
diff --git a/gnome-initial-setup/gis-driver.c b/gnome-initial-setup/gis-driver.c
index 14b62e0..ae42d52 100644
--- a/gnome-initial-setup/gis-driver.c
+++ b/gnome-initial-setup/gis-driver.c
@@ -502,22 +502,43 @@ gis_driver_hide_window (GisDriver *driver)
   gtk_widget_hide (GTK_WIDGET (priv->main_window));
 }
 
-static void
-load_vendor_conf_file (GisDriver *driver)
+static GKeyFile *
+load_vendor_conf_file_at_path (const char *path)
 {
-  GisDriverPrivate *priv = gis_driver_get_instance_private (driver);
   g_autoptr(GError) error = NULL;
   g_autoptr(GKeyFile) vendor_conf_file = g_key_file_new ();
 
-  if(!g_key_file_load_from_file (vendor_conf_file, VENDOR_CONF_FILE,
-                                 G_KEY_FILE_NONE, &error))
+  if (!g_key_file_load_from_file (vendor_conf_file, path, G_KEY_FILE_NONE, &error))
     {
       if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
-        g_warning ("Could not read file %s: %s", VENDOR_CONF_FILE, error->message);
-      return;
+        g_warning ("Could not read file %s: %s:", path, error->message);
+      return NULL;
     }
 
-  priv->vendor_conf_file = g_steal_pointer (&vendor_conf_file);
+  return g_steal_pointer (&vendor_conf_file);
+}
+
+static void
+load_vendor_conf_file (GisDriver *driver)
+{
+  GisDriverPrivate *priv = gis_driver_get_instance_private (driver);
+
+#ifdef VENDOR_CONF_FILE
+  priv->vendor_conf_file = load_vendor_conf_file_at_path (VENDOR_CONF_FILE);
+#else
+  /* If no path was passed at build time, then we have search path:
+   *
+   *  - First check $(sysconfdir)/gnome-initial-setup/vendor.conf
+   *  - Then check $(datadir)/gnome-initial-setup/vendor.conf
+   *
+   * This allows distributions to provide a default packaged config in a
+   * location that might be managed by ostree, and allows OEMs to
+   * override using an unmanaged location.
+   */
+  priv->vendor_conf_file = load_vendor_conf_file_at_path (PKGSYSCONFDIR "/vendor.conf");
+  if (priv->vendor_conf_file == NULL)
+    priv->vendor_conf_file = load_vendor_conf_file_at_path (PKGDATADIR "/vendor.conf");
+#endif
 }
 
 static void
@@ -525,10 +546,16 @@ report_conf_error_if_needed (const gchar *group,
                              const gchar *key,
                              const GError *error)
 {
+#if VENDOR_CONF_FILE
+  const char *file = VENDOR_CONF_FILE;
+#else
+  const char *file = "vendor.conf";
+#endif
+
   if (!g_error_matches (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND) &&
       !g_error_matches (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND))
     g_warning ("Error getting the value for key '%s' of group [%s] in "
-               "%s: %s", group, key, VENDOR_CONF_FILE, error->message);
+               "%s: %s", group, key, file, error->message);
 }
 
 gboolean
diff --git a/meson.build b/meson.build
index f1866ef..838ff56 100644
--- a/meson.build
+++ b/meson.build
@@ -14,19 +14,16 @@ po_dir = join_paths(meson.source_root(), 'po')
 data_dir = join_paths(prefix, get_option('datadir'))
 locale_dir = join_paths(prefix, get_option('localedir'))
 libexec_dir = join_paths(prefix, get_option('libexecdir'))
+sysconf_dir = join_paths(prefix, get_option('sysconfdir'))
 source_root = join_paths(meson.source_root(), 'gnome-initial-setup')
 pkgdata_dir = join_paths(data_dir, meson.project_name())
-
-vendor_conf_file = get_option('vendor-conf-file')
-if vendor_conf_file == ''
-    vendor_conf_file = join_paths(data_dir, 'gnome-initial-setup', 'vendor.conf')
-endif
+pkgsysconf_dir = join_paths(sysconf_dir, meson.project_name())
 
 conf = configuration_data()
-conf.set_quoted('VENDOR_CONF_FILE', vendor_conf_file)
 conf.set_quoted('GETTEXT_PACKAGE', meson.project_name())
 conf.set_quoted('GNOMELOCALEDIR', locale_dir)
 conf.set_quoted('PKGDATADIR', pkgdata_dir)
+conf.set_quoted('PKGSYSCONFDIR', pkgsysconf_dir)
 conf.set('SECRET_API_SUBJECT_TO_CHANGE', true)
 conf.set_quoted('G_LOG_DOMAIN', 'InitialSetup')
 conf.set('GLIB_VERSION_MIN_REQUIRED', 'GLIB_VERSION_2_64')
@@ -53,6 +50,11 @@ if enable_systemd
     systemd_userunitdir = join_paths(prefix, 'lib', 'systemd', 'user')
 endif
 
+vendor_conf_file = get_option('vendor-conf-file')
+if vendor_conf_file != ''
+    conf.set_quoted('VENDOR_CONF_FILE', vendor_conf_file)
+endif
+
 # Needed for the 'account' page
 cheese_dep = dependency ('cheese',
                          version: '>= 3.28',
diff --git a/meson_options.txt b/meson_options.txt
index 741e844..be386b5 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,6 +1,6 @@
 option('vendor-conf-file',
        type: 'string',
-       description: 'points to a keyfile containing vendor customization'
+       description: 'points to a keyfile containing vendor customization, use this only to override the 
usual search path'
 )
 
 option('cheese',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]