SDL: Don't fail joystick initialization if udev isn't available

From 5e8486bb29a917e06d2248677a654ac94b0cbcbd Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 25 Mar 2024 11:29:03 -0700
Subject: [PATCH] Don't fail joystick initialization if udev isn't available

---
 src/joystick/linux/SDL_sysjoystick.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c
index b2a96a2818614..e67b8e078b312 100644
--- a/src/joystick/linux/SDL_sysjoystick.c
+++ b/src/joystick/linux/SDL_sysjoystick.c
@@ -1042,21 +1042,24 @@ static int LINUX_JoystickInit(void)
     }
 
     if (enumeration_method == ENUMERATION_LIBUDEV) {
-        if (SDL_UDEV_Init() < 0) {
-            return SDL_SetError("Could not initialize UDEV");
-        }
+        if (SDL_UDEV_Init() == 0) {
+            /* Set up the udev callback */
+            if (SDL_UDEV_AddCallback(joystick_udev_callback) < 0) {
+                SDL_UDEV_Quit();
+                return SDL_SetError("Could not set up joystick <-> udev callback");
+            }
 
-        /* Set up the udev callback */
-        if (SDL_UDEV_AddCallback(joystick_udev_callback) < 0) {
-            SDL_UDEV_Quit();
-            return SDL_SetError("Could not set up joystick <-> udev callback");
+            /* Force a scan to build the initial device list */
+            SDL_UDEV_Scan();
+        } else {
+            SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
+                         "udev init failed, disabling udev integration");
+            enumeration_method = ENUMERATION_FALLBACK;
         }
-
-        /* Force a scan to build the initial device list */
-        SDL_UDEV_Scan();
-    } else
+    }
 #endif
-    {
+
+    if (enumeration_method != ENUMERATION_LIBUDEV) {
 #ifdef HAVE_INOTIFY
         inotify_fd = SDL_inotify_init1();