Bug 1472611 - Don't link DBus 1.5.12 symbol dbus_validate_bus_name(), r=stransky
authorozoder <ozoder@redhat.com>
Wed, 04 Jul 2018 09:24:34 +0200
changeset 425422 6ace78c3a8a5
parent 425421 7d3fe27beec5
child 425423 477570df4195
push id34245
push userdluca@mozilla.com
push dateSat, 07 Jul 2018 10:29:39 +0000
treeherdermozilla-central@1df83f663c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstransky
bugs1472611
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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,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;
   }