Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: base/native_library_linux.cc

Issue 6864020: linux: don't always print dlopen errors from LoadNativeLibrary (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/native_library.h" 5 #include "base/native_library.h"
6 6
7 #include <dlfcn.h> 7 #include <dlfcn.h>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/threading/thread_restrictions.h" 11 #include "base/threading/thread_restrictions.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 13
14 namespace base { 14 namespace base {
15 15
16 // static 16 // static
17 NativeLibrary LoadNativeLibrary(const FilePath& library_path) { 17 NativeLibrary LoadNativeLibrary(const FilePath& library_path,
18 std::string* error) {
18 // dlopen() opens the file off disk. 19 // dlopen() opens the file off disk.
19 base::ThreadRestrictions::AssertIOAllowed(); 20 base::ThreadRestrictions::AssertIOAllowed();
20 21
21 // We deliberately do not use RTLD_DEEPBIND. For the history why, please 22 // We deliberately do not use RTLD_DEEPBIND. For the history why, please
22 // refer to the bug tracker. Some useful bug reports to read include: 23 // refer to the bug tracker. Some useful bug reports to read include:
23 // http://crbug.com/17943, http://crbug.com/17557, http://crbug.com/36892, 24 // http://crbug.com/17943, http://crbug.com/17557, http://crbug.com/36892,
24 // and http://crbug.com/40794. 25 // and http://crbug.com/40794.
25 void* dl = dlopen(library_path.value().c_str(), RTLD_LAZY); 26 void* dl = dlopen(library_path.value().c_str(), RTLD_LAZY);
26 if (!dl) { 27 if (!dl && error)
27 std::string error_message = dlerror(); 28 *error = dlerror();
28 // Some obsolete plugins depend on libxul or libxpcom.
29 // Ignore the error messages when failing to load these.
30 if (error_message.find("libxul.so") == std::string::npos &&
31 error_message.find("libxpcom.so") == std::string::npos) {
32 LOG(ERROR) << "dlopen failed when trying to open " << library_path.value()
33 << ": " << error_message;
34 }
35 }
36 29
37 return dl; 30 return dl;
38 } 31 }
39 32
40 // static 33 // static
41 void UnloadNativeLibrary(NativeLibrary library) { 34 void UnloadNativeLibrary(NativeLibrary library) {
42 int ret = dlclose(library); 35 int ret = dlclose(library);
43 if (ret < 0) { 36 if (ret < 0) {
44 LOG(ERROR) << "dlclose failed: " << dlerror(); 37 LOG(ERROR) << "dlclose failed: " << dlerror();
45 NOTREACHED(); 38 NOTREACHED();
46 } 39 }
47 } 40 }
48 41
49 // static 42 // static
50 void* GetFunctionPointerFromNativeLibrary(NativeLibrary library, 43 void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
51 const char* name) { 44 const char* name) {
52 return dlsym(library, name); 45 return dlsym(library, name);
53 } 46 }
54 47
55 // static 48 // static
56 string16 GetNativeLibraryName(const string16& name) { 49 string16 GetNativeLibraryName(const string16& name) {
57 return ASCIIToUTF16("lib") + name + ASCIIToUTF16(".so"); 50 return ASCIIToUTF16("lib") + name + ASCIIToUTF16(".so");
58 } 51 }
59 52
60 } // namespace base 53 } // namespace base
OLDNEW
« no previous file with comments | « base/native_library.h ('k') | base/native_library_mac.mm » ('j') | base/native_library_mac.mm » ('J')

Powered by Google App Engine
This is Rietveld 408576698