28 int main(
int argc,
char **argv) {
30 int opterr_save = opterr;
33 char **optv =
reinterpret_cast<char **
>(smalloc(optc *
sizeof(
char *)));
34 for (
int i = 0; i < optc; ++i) {
35 optv[i] = strdup(argv[i]);
39 unsigned enforce_libfuse = 0;
42 while ((c = getopt(optc, optv,
"do:")) != -1) {
48 std::vector<std::string> mount_options =
SplitString(optarg,
',');
49 for (
unsigned i = 0; i < mount_options.size(); ++i) {
50 if (mount_options[i] ==
"debug") {
54 if (
HasPrefix(mount_options[i],
"libfuse=",
false )) {
55 std::vector<std::string> t =
SplitString(mount_options[i],
'=');
59 "Debug: enforcing libfuse version %u", enforce_libfuse);
68 for (
int i = 0; i < optc; ++i) {
76 std::string error_messages;
78 if (enforce_libfuse > 0) {
79 if ((enforce_libfuse < 2) || (enforce_libfuse > 3)) {
81 "Error: invalid libfuse version '%u', valid values are 2 or 3.",
87 std::string local_lib_path =
"./";
88 if (getenv(
"CVMFS_LIBRARY_PATH") != NULL) {
89 local_lib_path = getenv(
"CVMFS_LIBRARY_PATH");
90 if (!local_lib_path.empty() && (*local_lib_path.rbegin() !=
'/'))
91 local_lib_path.push_back(
'/');
95 std::vector<std::string> library_paths;
96 if ((enforce_libfuse == 0) || (enforce_libfuse == 3)) {
97 library_paths.push_back(local_lib_path + libname_fuse3);
98 library_paths.push_back(
"/usr/lib/" + libname_fuse3);
99 library_paths.push_back(
"/usr/lib64/" + libname_fuse3);
101 library_paths.push_back(
"/usr/local/lib/" + libname_fuse3);
104 if ((enforce_libfuse == 0) || (enforce_libfuse == 2)) {
105 library_paths.push_back(local_lib_path + libname_fuse2);
106 library_paths.push_back(
"/usr/lib/" + libname_fuse2);
107 library_paths.push_back(
"/usr/lib64/" + libname_fuse2);
109 library_paths.push_back(
"/usr/local/lib/" + libname_fuse2);
113 void *library_handle;
114 std::vector<std::string>::const_iterator i = library_paths.begin();
115 std::vector<std::string>::const_iterator iend = library_paths.end();
116 for (; i != iend; ++i) {
117 library_handle = dlopen(i->c_str(), RTLD_NOW | RTLD_LOCAL);
118 if (library_handle != NULL) {
126 error_messages += std::string(dlerror()) +
"\n";
129 if (!library_handle) {
131 "Error: failed to load cvmfs library, tried: '%s'\n%s",
132 JoinStrings(library_paths,
"' '").c_str(), error_messages.c_str());
137 dlsym(library_handle,
"g_cvmfs_stub_exports"));
138 if (exports_ptr == NULL) {
140 "Error: symbol g_cvmfs_stub_exports not found");
144 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,...)