diff options
author | Patrick Griffis <pgriffis@igalia.com> | 2022-01-18 18:38:52 -0600 |
---|---|---|
committer | Patrick Griffis <pgriffis@igalia.com> | 2022-01-21 15:21:37 -0600 |
commit | 4e837bc0a389ba73d118a02c2e39236cf59ee97d (patch) | |
tree | 224795b019c26c016e352458b43fb2287658cfc6 | |
parent | 4aa70d2d7201e44c7259bf5aeae90beb733e331f (diff) | |
download | flatpak-4e837bc0a389ba73d118a02c2e39236cf59ee97d.tar.gz |
Add have-kernel-module conditionalpgriffis/have-nvidia-gpu
This is useful for extensions that apply to specific hardware.
-rw-r--r-- | common/flatpak-utils.c | 54 | ||||
-rw-r--r-- | doc/flatpak-metadata.xml | 8 |
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 |