| 492 | |
| 493 | |
| 494 | static CvmfsExports *LoadLibrary(const bool debug_mode, |
| 495 | LoaderExports *loader_exports) { |
| 496 | std::string local_lib_path = "./"; |
| 497 | if (getenv("CVMFS_LIBRARY_PATH") != NULL) { |
| 498 | local_lib_path = getenv("CVMFS_LIBRARY_PATH"); |
| 499 | if (!local_lib_path.empty() && (*local_lib_path.rbegin() != '/')) |
| 500 | local_lib_path.push_back('/'); |
| 501 | } |
| 502 | |
| 503 | #if CVMFS_USE_LIBFUSE == 2 |
| 504 | string library_name = string("cvmfs_fuse") + ((debug_mode) ? "_debug" : ""); |
| 505 | #else |
| 506 | string library_name = string("cvmfs_fuse3") + ((debug_mode) ? "_debug" : ""); |
| 507 | #endif |
| 508 | library_name = platform_libname(library_name); |
| 509 | string error_messages; |
| 510 | |
| 511 | vector<string> library_paths; // TODO(rmeusel): C++11 initializer |
| 512 | if (library_paths.empty()) { |
| 513 | library_paths.push_back(local_lib_path + library_name); |
| 514 | library_paths.push_back("/usr/lib/" + library_name); |
| 515 | library_paths.push_back("/usr/lib64/" + library_name); |
| 516 | #ifdef __APPLE__ |
| 517 | // Since OS X El Capitan (10.11) came with SIP, we needed to relocate our |
| 518 | // binaries from /usr/... to /usr/local/... |
| 519 | library_paths.push_back("/usr/local/lib/" + library_name); |
| 520 | #endif |
| 521 | } |
| 522 | |
| 523 | vector<string>::const_iterator i = library_paths.begin(); |
| 524 | const vector<string>::const_iterator iend = library_paths.end(); |
| 525 | for (; i != iend; ++i) { // TODO(rmeusel): C++11 range based for |
| 526 | library_handle_ = OpenLibrary(*i); |
| 527 | if (library_handle_ != NULL) { |
| 528 | break; |
| 529 | } |
| 530 | |
| 531 | error_messages += string(dlerror()) + "\n"; |
| 532 | } |
| 533 | |
| 534 | if (!library_handle_) { |
| 535 | LogCvmfs(kLogCvmfs, kLogStderr | kLogSyslogErr, |
| 536 | "failed to load cvmfs library, tried: '%s'\n%s", |
| 537 | JoinStrings(library_paths, "' '").c_str(), error_messages.c_str()); |
| 538 | return NULL; |
| 539 | } |
| 540 | |
| 541 | CvmfsExports **exports_ptr = reinterpret_cast<CvmfsExports **>( |
| 542 | dlsym(library_handle_, "g_cvmfs_exports")); |
| 543 | if (!exports_ptr) |
| 544 | return NULL; |
| 545 | |
| 546 | if (loader_exports) { |
| 547 | LoadEvent *load_event = new LoadEvent(); |
| 548 | load_event->timestamp = time(NULL); |
| 549 | load_event->so_version = (*exports_ptr)->so_version; |
| 550 | loader_exports->history.push_back(load_event); |
| 551 | } |
no test coverage detected