summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Griffis <pgriffis@igalia.com>2022-01-18 18:38:52 -0600
committerPatrick <tingping@tingping.se>2022-01-22 07:39:00 -0600
commit49a829cc0ba461059f67ba6b89f576709cb1bf7d (patch)
treee6664cc295d8415f60f19ecda2b358a55f7fb490
parent7bec38c9d122d2dbcc8f3cf6017afe1fbf1d71d8 (diff)
downloadflatpak-master.tar.gz
Add have-kernel-module conditionalmaster
This is useful for extensions that apply to specific hardware.
-rw-r--r--common/flatpak-utils.c54
-rw-r--r--doc/flatpak-metadata.xml8
2 files changed, 62 insertions, 0 deletions
diff --git a/common/flatpak-utils.c b/common/flatpak-utils.c
index 3259188e..e77b8790 100644
--- a/common/flatpak-utils.c
+++ b/common/flatpak-utils.c
@@ -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-");
diff --git a/doc/flatpak-metadata.xml b/doc/flatpak-metadata.xml
index 2d853ade..ad624931 100644
--- a/doc/flatpak-metadata.xml
+++ b/doc/flatpak-metadata.xml
@@ -893,6 +893,14 @@
<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>
Is true if the suffix (case-insensitively) is in the