From 6eeb0d3c513e7739bfdf7e63a7850a6d3b798da1 Mon Sep 17 00:00:00 2001 From: Kyle Machulis Date: Tue, 19 Nov 2013 12:52:37 -0800 Subject: [PATCH] Bug 937496 - Check if libudev already loaded before trying to load symbols from it; r=ted --- hal/linux/udev.h | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/hal/linux/udev.h b/hal/linux/udev.h index 049b20357ea..9c29c2905bf 100644 --- a/hal/linux/udev.h +++ b/hal/linux/udev.h @@ -30,13 +30,27 @@ class udev_lib { // 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() {