linux: If D-Bus isn't available on the system, don't keep trying to load it. Fixes Bugzilla #4476.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
diff --git a/src/core/linux/SDL_dbus.c b/src/core/linux/SDL_dbus.c
index 40b3bd3..4ea3b12 100644
--- a/src/core/linux/SDL_dbus.c
+++ b/src/core/linux/SDL_dbus.c
@@ -111,8 +111,19 @@ LoadDBUSLibrary(void)
void
SDL_DBus_Init(void)
{
- if (!dbus.session_conn && LoadDBUSLibrary() != -1) {
+ static SDL_bool is_dbus_available = SDL_TRUE;
+ if (!is_dbus_available) {
+ return; /* don't keep trying if this fails. */
+ }
+
+ if (!dbus.session_conn) {
DBusError err;
+
+ if (LoadDBUSLibrary() == -1) {
+ is_dbus_available = SDL_FALSE; /* can't load at all? Don't keep trying. */
+ return; /* oh well */
+ }
+
dbus.error_init(&err);
dbus.session_conn = dbus.bus_get_private(DBUS_BUS_SESSION, &err);
if (!dbus.error_is_set(&err)) {
@@ -121,6 +132,7 @@ SDL_DBus_Init(void)
if (dbus.error_is_set(&err)) {
dbus.error_free(&err);
SDL_DBus_Quit();
+ is_dbus_available = SDL_FALSE;
return; /* oh well */
}
dbus.connection_set_exit_on_disconnect(dbus.system_conn, 0);
@@ -154,15 +166,11 @@ SDL_DBus_Quit(void)
SDL_DBusContext *
SDL_DBus_GetContext(void)
{
- if(!dbus_handle || !dbus.session_conn){
+ if (!dbus_handle || !dbus.session_conn) {
SDL_DBus_Init();
}
- if(dbus_handle && dbus.session_conn){
- return &dbus;
- } else {
- return NULL;
- }
+ return (dbus_handle && dbus.session_conn) ? &dbus : NULL;
}
static SDL_bool