Bug 1472611 - Don't link DBus 1.5.12 symbol dbus_validate_bus_name(), r?stransky draft
authorozoder <ozoder@redhat.com>
Wed, 04 Jul 2018 09:24:34 +0200
changeset 813947 ea7f18dd343d1e02daf77fea6a5f9264bb258129
parent 813581 a0e47ebc4c06e652b919dabee711fdbd6bfd31b5
push id115057
push userbmo:ozoder@redhat.com
push dateWed, 04 Jul 2018 07:27:34 +0000
reviewersstransky
bugs1472611
milestone63.0a1
Bug 1472611 - Don't link DBus 1.5.12 symbol dbus_validate_bus_name(), r?stransky MozReview-Commit-ID: 6scVh8DOex2
toolkit/components/remote/nsDBusRemoteService.cpp
widget/xremoteclient/DBusRemoteClient.cpp
--- a/toolkit/components/remote/nsDBusRemoteService.cpp
+++ b/toolkit/components/remote/nsDBusRemoteService.cpp
@@ -22,16 +22,18 @@
 
 #include "nsCOMPtr.h"
 
 #include "nsGTKToolkit.h"
 
 #include <dbus/dbus.h>
 #include <dbus/dbus-glib-lowlevel.h>
 
+#include <dlfcn.h>
+
 NS_IMPL_ISUPPORTS(nsDBusRemoteService,
                   nsIRemoteService)
 
 NS_IMETHODIMP
 nsDBusRemoteService::RegisterWindow(mozIDOMWindow* aWindow)
 {
   // We don't listen for property change events on DBus remote
   return NS_ERROR_NOT_IMPLEMENTED;
@@ -184,20 +186,24 @@ nsDBusRemoteService::Startup(const char*
   profileName.ReplaceChar("+/=", '_');
 
   nsAutoCString busName;
   busName = nsPrintfCString("org.mozilla.%s.%s", mAppName.get(),
                                                  profileName.get());
   if (busName.Length() > DBUS_MAXIMUM_NAME_LENGTH)
     busName.Truncate(DBUS_MAXIMUM_NAME_LENGTH);
 
+  static auto sDBusValidateBusName =
+      (bool (*)(const char *, DBusError *))
+      dlsym(RTLD_DEFAULT, "dbus_validate_bus_name");
+
   // We don't have a valid busName yet - try to create a default one.
-  if (!dbus_validate_bus_name(busName.get(), nullptr)) {
+  if (!sDBusValidateBusName(busName.get(), nullptr)) {
     busName = nsPrintfCString("org.mozilla.%s.%s", mAppName.get(), "default");
-    if (!dbus_validate_bus_name(busName.get(), nullptr)) {
+    if (!sDBusValidateBusName(busName.get(), nullptr)) {
       // We failed completelly to get a valid bus name - just quit
       // to prevent crash at dbus_bus_request_name().
       return NS_ERROR_FAILURE;
     }
   }
 
   DBusError err;
   dbus_error_init(&err);
--- a/widget/xremoteclient/DBusRemoteClient.cpp
+++ b/widget/xremoteclient/DBusRemoteClient.cpp
@@ -7,16 +7,18 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "DBusRemoteClient.h"
 #include "RemoteUtils.h"
 #include "mozilla/Logging.h"
 #include "mozilla/Base64.h"
 #include "nsPrintfCString.h"
 
+#include <dlfcn.h>
+
 using mozilla::LogLevel;
 static mozilla::LazyLogModule sRemoteLm("DBusRemoteClient");
 
 DBusRemoteClient::DBusRemoteClient()
 {
   mConnection = nullptr;
   MOZ_LOG(sRemoteLm, LogLevel::Debug, ("DBusRemoteClient::DBusRemoteClient"));
 }
@@ -131,21 +133,25 @@ DBusRemoteClient::GetRemoteDestinationNa
     NS_ENSURE_SUCCESS(rv, false);
     profileName.ReplaceChar("+/=", '_');
 
     aDestinationName = nsPrintfCString("org.mozilla.%s.%s", aProgram,
                                                             profileName.get());
     if (aDestinationName.Length() > DBUS_MAXIMUM_NAME_LENGTH)
       aDestinationName.Truncate(DBUS_MAXIMUM_NAME_LENGTH);
 
-    if (!dbus_validate_bus_name(aDestinationName.get(), nullptr)) {
+    static auto sDBusValidateBusName =
+      (bool (*)(const char *, DBusError *))
+      dlsym(RTLD_DEFAULT, "dbus_validate_bus_name");
+
+    if (!sDBusValidateBusName(aDestinationName.get(), nullptr)) {
       // We don't have a valid busName yet - try to create a default one.
       aDestinationName = nsPrintfCString("org.mozilla.%s.%s", aProgram,
                                                              "default");
-      if (!dbus_validate_bus_name(aDestinationName.get(), nullptr)) {
+      if (!sDBusValidateBusName(aDestinationName.get(), nullptr)) {
         // We failed completelly to get a valid bus name - just quit
         // to prevent crash at dbus_bus_request_name().
         return false;
       }
     }
 
     return true;
   }