Add have-kernel-module conditional

This is useful for extensions that apply to specific hardware.
This commit is contained in:
Patrick Griffis
2022-01-18 18:38:52 -06:00
committed by Patrick
parent 7bec38c9d1
commit 49a829cc0b
2 changed files with 62 additions and 0 deletions

View File

@@ -616,6 +616,53 @@ flatpak_get_have_intel_gpu (void)
return have_intel;
}
static GHashTable *
load_kernel_module_list (void)
{
GHashTable *modules = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
g_autofree char *modules_data = NULL;
g_autoptr(GError) error = NULL;
char *start, *end;
if (!g_file_get_contents ("/proc/modules", &modules_data, NULL, &error))
{
g_debug ("Failed to read /proc/modules: %s", error->message);
return modules;
}
/* /proc/modules is a table of modules.
* Columns are split by spaces and rows by newlines.
* The first column is the name. */
start = modules_data;
while (TRUE)
{
end = strchr (start, ' ');
if (end == NULL)
break;
g_hash_table_add (modules, g_strndup (start, (end - start)));
start = strchr (end, '\n');
if (start == NULL)
break;
start++;
}
return modules;
}
static gboolean
flatpak_get_have_kernel_module (const char *module_name)
{
static GHashTable *kernel_modules = NULL;
if (g_once_init_enter (&kernel_modules))
g_once_init_leave (&kernel_modules, load_kernel_module_list ());
return g_hash_table_contains (kernel_modules, module_name);
}
static const char *
flatpak_get_gtk_theme (void)
{
@@ -5991,6 +6038,13 @@ flatpak_extension_matches_reason (const char *extension_id,
if (flatpak_get_have_intel_gpu ())
return TRUE;
}
else if (g_str_has_prefix (reason, "have-kernel-module-"))
{
const char *module_name = reason + strlen ("have-kernel-module-");
if (flatpak_get_have_kernel_module (module_name))
return TRUE;
}
else if (g_str_has_prefix (reason, "on-xdg-desktop-"))
{
const char *desktop_name = reason + strlen ("on-xdg-desktop-");

View File

@@ -892,6 +892,14 @@
<term><option>have-intel-gpu</option></term>
<para>Is true if the i915 kernel module is loaded. Added 0.10.1.</para>
</varlistentry>
<varlistentry>
<term><option>have-kernel-module-*</option></term>
<para>
Is true if the suffix (case-sensitive) is found in <literal>/proc/modules</literal>.
For example <literal>have-kernel-module-nvidia</literal>.
Added 1.13.2.
</para>
</varlistentry>
<varlistentry>
<term><option>on-xdg-desktop-*</option></term>
<para>