Browse Source

joystick: Don't use udev in Flatpak or pressure-vessel container
Flatpak[1] and pressure-vessel[2] are known to use user namespaces,
therefore udev event notification via netlink won't work reliably.
Both frameworks provide a filesystem API that libraries can use to
detect them. Do that, and automatically fall back from udev-based
device discovery to the inotify-based fallback introduced in Bug #5337.

[1] <https://flatpak.org/>
[2] <https://gitlab.steamos.cloud/steamrt/steam-runtime-tools/-/tree/master/pressure-vessel>

Signed-off-by: Simon McVittie <smcv@collabora.com>

Simon McVittie 4 years ago
parent
commit
8e2746cfb6
1 changed files with 10 additions and 0 deletions
  1. 10 0
      src/joystick/linux/SDL_sysjoystick.c

+ 10 - 0
src/joystick/linux/SDL_sysjoystick.c

@@ -635,9 +635,19 @@ LINUX_JoystickInit(void)
 #if SDL_USE_LIBUDEV
     if (enumeration_method == ENUMERATION_UNSET) {
         if (SDL_getenv("SDL_JOYSTICK_DISABLE_UDEV") != NULL) {
+            SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
+                         "udev disabled by SDL_JOYSTICK_DISABLE_UDEV");
+            enumeration_method = ENUMERATION_FALLBACK;
+        }
+        else if (access("/.flatpak-info", F_OK) == 0
+                 || access("/run/pressure-vessel", F_OK) == 0) {
+            SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
+                         "Container detected, disabling udev integration");
             enumeration_method = ENUMERATION_FALLBACK;
         }
         else {
+            SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
+                         "Using udev for joystick device discovery");
             enumeration_method = ENUMERATION_LIBUDEV;
         }
     }