From 1e8f074c4339ca8fbdec4f77042dc04420e29775 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 29 Nov 2016 05:34:20 -0800 Subject: [PATCH] Avoid conflicts with multiple versions of udev by first trying the library that is linked with the executable, if any, and then picking the one that is in the build environment. This fixes joystick detection for applications using the Steam Linux Runtime --- configure | 10 ++++++++++ configure.in | 6 ++++++ include/SDL_config.h.in | 3 +++ src/core/linux/SDL_dbus.c | 2 ++ src/core/linux/SDL_ibus.c | 2 ++ src/core/linux/SDL_ime.c | 2 ++ src/core/linux/SDL_udev.c | 19 ++++++++++++++++--- 7 files changed, 41 insertions(+), 3 deletions(-) diff --git a/configure b/configure index 08e73c5f00834..173b9e79a3d3e 100755 --- a/configure +++ b/configure @@ -21578,6 +21578,16 @@ fi $as_echo "#define HAVE_LIBUDEV_H 1" >>confdefs.h + + udev_lib=`find_lib "libudev.so.*" "" | sed 's/.*\/\(.*\)/\1/; q'` + if test x$udev_lib != x; then + echo "-- dynamic udev -> $udev_lib" + +cat >>confdefs.h <<_ACEOF +#define SDL_UDEV_DYNAMIC "$udev_lib" +_ACEOF + + fi fi fi } diff --git a/configure.in b/configure.in index 801d2f198c8eb..bf67b0abf546e 100644 --- a/configure.in +++ b/configure.in @@ -2231,6 +2231,12 @@ AC_HELP_STRING([--enable-libudev], [enable libudev support [[default=yes]]]), have_libudev_h_hdr=no) if test x$have_libudev_h_hdr = xyes; then AC_DEFINE(HAVE_LIBUDEV_H, 1, [ ]) + + udev_lib=[`find_lib "libudev.so.*" "" | sed 's/.*\/\(.*\)/\1/; q'`] + if test x$udev_lib != x; then + echo "-- dynamic udev -> $udev_lib" + AC_DEFINE_UNQUOTED(SDL_UDEV_DYNAMIC, "$udev_lib", [ ]) + fi fi fi } diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in index 850866ab7e949..f953cb0d987b0 100644 --- a/include/SDL_config.h.in +++ b/include/SDL_config.h.in @@ -360,4 +360,7 @@ /* Enable ime support */ #undef SDL_USE_IME +/* Enable dynamic udev support */ +#undef SDL_UDEV_DYNAMIC + #endif /* SDL_config_h_ */ diff --git a/src/core/linux/SDL_dbus.c b/src/core/linux/SDL_dbus.c index ab73ca17c93d1..332113d8a8901 100644 --- a/src/core/linux/SDL_dbus.c +++ b/src/core/linux/SDL_dbus.c @@ -237,3 +237,5 @@ SDL_DBus_ScreensaverInhibit(SDL_bool inhibit) } } #endif + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/core/linux/SDL_ibus.c b/src/core/linux/SDL_ibus.c index 3d63b8b30c3e2..33ef6ac7e8844 100644 --- a/src/core/linux/SDL_ibus.c +++ b/src/core/linux/SDL_ibus.c @@ -680,3 +680,5 @@ SDL_IBus_PumpEvents(void) } #endif + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/core/linux/SDL_ime.c b/src/core/linux/SDL_ime.c index 049bd6e02e996..4809b242132a1 100644 --- a/src/core/linux/SDL_ime.c +++ b/src/core/linux/SDL_ime.c @@ -136,3 +136,5 @@ SDL_IME_PumpEvents() if (SDL_IME_PumpEvents_Real) SDL_IME_PumpEvents_Real(); } + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/core/linux/SDL_udev.c b/src/core/linux/SDL_udev.c index 351ecf3c7174c..a0b168d8597bd 100644 --- a/src/core/linux/SDL_udev.c +++ b/src/core/linux/SDL_udev.c @@ -33,7 +33,14 @@ #include "SDL.h" -static const char* SDL_UDEV_LIBS[] = { "libudev.so.1", "libudev.so.0" }; +static const char *SDL_UDEV_LIBS[] = { +#ifdef SDL_UDEV_DYNAMIC + SDL_UDEV_DYNAMIC +#else + "libudev.so.1", + "libudev.so.0" +#endif +}; #define _THIS SDL_UDEV_PrivateData *_this static _THIS = NULL; @@ -252,8 +259,12 @@ SDL_UDEV_LoadLibrary(void) if (_this == NULL) { return SDL_SetError("UDEV not initialized"); } - - + + /* See if there is a udev library already loaded */ + if (SDL_UDEV_load_syms() == 0) { + return 0; + } + if (_this->udev_handle == NULL) { for( i = 0 ; i < SDL_arraysize(SDL_UDEV_LIBS); i++) { _this->udev_handle = SDL_LoadObject(SDL_UDEV_LIBS[i]); @@ -536,3 +547,5 @@ SDL_UDEV_DelCallback(SDL_UDEV_Callback cb) #endif /* SDL_USE_LIBUDEV */ + +/* vi: set ts=4 sw=4 expandtab: */