Bug 937496 - Check if libudev already loaded before trying to load symbols from it; r=ted
authorKyle Machulis <kyle@nonpolynomial.com>
Tue, 19 Nov 2013 12:52:37 -0800
changeset 156448 65a409f10de6e19f0b3be56689d924656e80bfa9
parent 156447 6be9a40c54b63caf1b74c30f8faefa7bd356a4ad
child 156449 597712fa283f74e2dc6aa478f79ec39e27724d36
push id25678
push userryanvm@gmail.com
push dateWed, 20 Nov 2013 03:26:13 +0000
treeherdermozilla-central@4f993fa378eb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs937496
milestone28.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 937496 - Check if libudev already loaded before trying to load symbols from it; r=ted
hal/linux/udev.h
--- a/hal/linux/udev.h
+++ b/hal/linux/udev.h
@@ -25,23 +25,37 @@ struct udev_monitor;
 class udev_lib {
  public:
   udev_lib() : lib(nullptr),
                udev(nullptr) {
     // Be careful about ABI compat! 0 -> 1 didn't change any
     // symbols this code relies on, per:
     // https://lists.fedoraproject.org/pipermail/devel/2012-June/168227.html
     const char* lib_names[] = {"libudev.so.0", "libudev.so.1"};
+    // Check whether a library is already loaded so we don't load two
+    // conflicting libs.
     for (unsigned i = 0; i < ArrayLength(lib_names); i++) {
-      lib = dlopen(lib_names[i], RTLD_LAZY | RTLD_GLOBAL);
-      if (lib)
+      lib = dlopen(lib_names[i], RTLD_NOLOAD | RTLD_LAZY | RTLD_GLOBAL);
+      if (lib) {
         break;
+      }
     }
-    if (lib && LoadSymbols())
+    // If nothing loads the first time through, it means no version of libudev
+    // was already loaded.
+    if (!lib) {
+      for (unsigned i = 0; i < ArrayLength(lib_names); i++) {
+        lib = dlopen(lib_names[i], RTLD_LAZY | RTLD_GLOBAL);
+        if (lib) {
+          break;
+        }
+      }
+    }
+    if (lib && LoadSymbols()) {
       udev = udev_new();
+    }
   }
 
   ~udev_lib() {
     if (udev) {
       udev_unref(udev);
     }
 
     if (lib) {