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>
This commit is contained in:
Philip Withnall 2021-02-24 11:58:49 +00:00
parent daa62a35e1
commit 05ff2f877c
3 changed files with 20 additions and 6 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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')