From 8e2746cfb6e1f1a1da5088241a1440fd2535e321 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 23 Nov 2020 21:10:48 -0800 Subject: [PATCH] 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] [2] Signed-off-by: Simon McVittie --- src/joystick/linux/SDL_sysjoystick.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index 12832be18..93509583a 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/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; } }