29 int main(
int argc,
char **argv) {
31 int opterr_save = opterr;
34 char **optv =
reinterpret_cast<char **
>(smalloc(optc *
sizeof(
char *)));
35 for (
int i = 0; i < optc; ++i) {
36 optv[i] = strdup(argv[i]);
40 unsigned enforce_libfuse = 0;
43 while ((c = getopt(optc, optv,
"do:")) != -1) {
49 std::vector<std::string> mount_options =
SplitString(optarg,
',');
50 for (
unsigned i = 0; i < mount_options.size(); ++i) {
51 if (mount_options[i] ==
"debug") {
55 if (
HasPrefix(mount_options[i],
"libfuse=",
false )) {
56 std::vector<std::string> t =
SplitString(mount_options[i],
'=');
60 "Debug: enforcing libfuse version %u", enforce_libfuse);
69 for (
int i = 0; i < optc; ++i) {
77 std::string error_messages;
79 if (enforce_libfuse > 0) {
80 if ((enforce_libfuse < 2) || (enforce_libfuse > 3)) {
82 "Error: invalid libfuse version '%u', valid values are 2 or 3.",
88 std::string local_lib_path =
"./";
89 if (getenv(
"CVMFS_LIBRARY_PATH") != NULL) {
90 local_lib_path = getenv(
"CVMFS_LIBRARY_PATH");
91 if (!local_lib_path.empty() && (*local_lib_path.rbegin() !=
'/'))
92 local_lib_path.push_back(
'/');
96 std::vector<std::string> library_paths;
97 if ((enforce_libfuse == 0) || (enforce_libfuse == 3)) {
98 library_paths.push_back(local_lib_path + libname_fuse3);
99 library_paths.push_back(
"/usr/lib/" + libname_fuse3);
100 library_paths.push_back(
"/usr/lib64/" + libname_fuse3);
102 library_paths.push_back(
"/usr/local/lib/" + libname_fuse3);
105 if ((enforce_libfuse == 0) || (enforce_libfuse == 2)) {
106 library_paths.push_back(local_lib_path + libname_fuse2);
107 library_paths.push_back(
"/usr/lib/" + libname_fuse2);
108 library_paths.push_back(
"/usr/lib64/" + libname_fuse2);
110 library_paths.push_back(
"/usr/local/lib/" + libname_fuse2);
114 void *library_handle;
115 std::vector<std::string>::const_iterator i = library_paths.begin();
116 std::vector<std::string>::const_iterator iend = library_paths.end();
117 for (; i != iend; ++i) {
118 library_handle = dlopen(i->c_str(), RTLD_NOW | RTLD_LOCAL);
119 if (library_handle != NULL) {
127 error_messages += std::string(dlerror()) +
"\n";
130 if (!library_handle) {
132 "Error: failed to load cvmfs library, tried: '%s'\n%s",
133 JoinStrings(library_paths,
"' '").c_str(), error_messages.c_str());
138 dlsym(library_handle,
"g_cvmfs_stub_exports"));
139 if (exports_ptr == NULL) {
141 "Error: symbol g_cvmfs_stub_exports not found");
145 return (*exports_ptr)->fn_main(argc, argv);
string JoinStrings(const vector< string > &strings, const string &joint)
assert((mem||(size==0))&&"Out Of Memory")
vector< string > SplitString(const string &str, char delim)
bool HasPrefix(const string &str, const string &prefix, const bool ignore_case)
uint64_t String2Uint64(const string &value)
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)