linux: If D-Bus isn't available on the system, don't keep trying to load it.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 09 Oct 2019 19:38:16 -0400
changeset 13107074c42dbf8c9
parent 13106 11be7c38d220
child 13108 efa5fe44e4e8
linux: If D-Bus isn't available on the system, don't keep trying to load it.

Fixes Bugzilla #4476.
src/core/linux/SDL_dbus.c
     1.1 --- a/src/core/linux/SDL_dbus.c	Wed Oct 09 13:42:13 2019 -0400
     1.2 +++ b/src/core/linux/SDL_dbus.c	Wed Oct 09 19:38:16 2019 -0400
     1.3 @@ -111,8 +111,19 @@
     1.4  void
     1.5  SDL_DBus_Init(void)
     1.6  {
     1.7 -    if (!dbus.session_conn && LoadDBUSLibrary() != -1) {
     1.8 +    static SDL_bool is_dbus_available = SDL_TRUE;
     1.9 +    if (!is_dbus_available) {
    1.10 +        return;  /* don't keep trying if this fails. */
    1.11 +    }
    1.12 +
    1.13 +    if (!dbus.session_conn) {
    1.14          DBusError err;
    1.15 +
    1.16 +        if (LoadDBUSLibrary() == -1) {
    1.17 +            is_dbus_available = SDL_FALSE;  /* can't load at all? Don't keep trying. */
    1.18 +            return;  /* oh well */
    1.19 +        }
    1.20 +
    1.21          dbus.error_init(&err);
    1.22          dbus.session_conn = dbus.bus_get_private(DBUS_BUS_SESSION, &err);
    1.23          if (!dbus.error_is_set(&err)) {
    1.24 @@ -121,6 +132,7 @@
    1.25          if (dbus.error_is_set(&err)) {
    1.26              dbus.error_free(&err);
    1.27              SDL_DBus_Quit();
    1.28 +            is_dbus_available = SDL_FALSE;
    1.29              return;  /* oh well */
    1.30          }
    1.31          dbus.connection_set_exit_on_disconnect(dbus.system_conn, 0);
    1.32 @@ -154,15 +166,11 @@
    1.33  SDL_DBusContext *
    1.34  SDL_DBus_GetContext(void)
    1.35  {
    1.36 -    if(!dbus_handle || !dbus.session_conn){
    1.37 +    if (!dbus_handle || !dbus.session_conn) {
    1.38          SDL_DBus_Init();
    1.39      }
    1.40      
    1.41 -    if(dbus_handle && dbus.session_conn){
    1.42 -        return &dbus;
    1.43 -    } else {
    1.44 -        return NULL;
    1.45 -    }
    1.46 +    return (dbus_handle && dbus.session_conn) ? &dbus : NULL;
    1.47  }
    1.48  
    1.49  static SDL_bool