[glib: 3/7] gdbusprivate: Stop hard-coding path to /var/lib




commit 05ff2f877ca301096106991c4f455519b5695cad
Author: Philip Withnall <pwithnall endlessos org>
Date:   Wed Feb 24 11:58:49 2021 +0000

    gdbusprivate: Stop hard-coding path to /var/lib
    
    This will require distributions to ensure they pass
    `--localstatedir=/var` correctly to Meson, but they should be doing that
    already.
    
    See https://mesonbuild.com/Builtin-options.html#directories for details
    about how Meson treats `localstatedir` differently from most other `dir`
    variables.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 gio/gdbusprivate.c | 19 +++++++++++++------
 gio/meson.build    |  1 +
 meson.build        |  6 ++++++
 3 files changed, 20 insertions(+), 6 deletions(-)
---
diff --git a/gio/gdbusprivate.c b/gio/gdbusprivate.c
index 8bb52227a..282678f3b 100644
--- a/gio/gdbusprivate.c
+++ b/gio/gdbusprivate.c
@@ -2475,18 +2475,24 @@ _g_dbus_get_machine_id (GError **error)
   gsize i;
   gboolean non_zero = FALSE;
 
-  /* TODO: use PACKAGE_LOCALSTATEDIR ? */
-  if (!g_file_get_contents ("/var/lib/dbus/machine-id",
+  /* Copy what dbus.git does: allow the /var/lib path to be configurable at
+   * build time, but hard-code the system-wide machine ID path in /etc. */
+  const gchar *var_lib_path = LOCALSTATEDIR "/lib/dbus/machine-id";
+  const gchar *etc_path = "/etc/machine-id";
+
+  if (!g_file_get_contents (var_lib_path,
                             &ret,
                             NULL,
                             &first_error) &&
-      !g_file_get_contents ("/etc/machine-id",
+      !g_file_get_contents (etc_path,
                             &ret,
                             NULL,
                             NULL))
     {
       g_propagate_prefixed_error (error, g_steal_pointer (&first_error),
-                                  _("Unable to load /var/lib/dbus/machine-id or /etc/machine-id: "));
+                                  /* Translators: Both placeholders are file paths */
+                                  _("Unable to load %s or %s: "),
+                                  var_lib_path, etc_path);
       return NULL;
     }
 
@@ -2510,8 +2516,9 @@ _g_dbus_get_machine_id (GError **error)
 
   if (i != 32 || ret[i] != '\n' || ret[i + 1] != '\0' || !non_zero)
     {
-      g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
-                           "Invalid machine ID in /var/lib/dbus/machine-id or /etc/machine-id");
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                   "Invalid machine ID in %s or %s",
+                   var_lib_path, etc_path);
       g_free (ret);
       return NULL;
     }
diff --git a/gio/meson.build b/gio/meson.build
index 2bf1e1973..397882f75 100644
--- a/gio/meson.build
+++ b/gio/meson.build
@@ -2,6 +2,7 @@ gio_c_args = [
   '-DG_LOG_DOMAIN="GLib-GIO"',
   '-DGIO_COMPILATION',
   '-DGIO_MODULE_DIR="@0@"'.format(glib_giomodulesdir),
+  '-DLOCALSTATEDIR="@0@"'.format(glib_localstatedir),
 ]
 
 gio_c_args += glib_hidden_visibility_args
diff --git a/meson.build b/meson.build
index 2e3acbef6..816ff21c0 100644
--- a/meson.build
+++ b/meson.build
@@ -87,6 +87,12 @@ else
   glib_charsetaliasdir = glib_libdir
 endif
 
+glib_localstatedir = get_option('localstatedir')
+if not glib_localstatedir.startswith('/')
+  # See https://mesonbuild.com/Builtin-options.html#directories
+  glib_localstatedir = join_paths(glib_prefix, glib_localstatedir)
+endif
+
 installed_tests_metadir = join_paths(glib_datadir, 'installed-tests', meson.project_name())
 installed_tests_execdir = join_paths(glib_libexecdir, 'installed-tests', meson.project_name())
 installed_tests_enabled = get_option('installed_tests')


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