Bug 1472611 - Don't link DBus 1.5.12 symbol dbus_validate_bus_name(). r=stransky, a=RyanVM
authorozoder <ozoder@redhat.com>
Wed, 04 Jul 2018 09:24:34 +0200
changeset 473815 647313afaa4a
parent 473814 9567eb705574
child 473816 ad93c4fae965
push id1749
push userryanvm@gmail.com
push date2018-08-06 13:40 +0000
treeherdermozilla-release@b5d39c025741 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstransky, RyanVM
bugs1472611
milestone61.0.2
Bug 1472611 - Don't link DBus 1.5.12 symbol dbus_validate_bus_name(). r=stransky, a=RyanVM 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,27 @@ 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");
+  if (!sDBusValidateBusName) {
+    return NS_ERROR_FAILURE;
+  }
+
   // 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,28 @@ 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) {
+      return false
+    }
+
+    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;
   }