GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/fuse_main.cc
Date: 2026-10-04 02:40:33
Exec Total Coverage
Lines: 0 53 0.0%
Branches: 0 33 0.0%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 *
4 * The Fuse module entry point. Loads the cvmfs fuse module (libcvmfs_fuse3),
5 * in debug or normal flavour depending on the mount options.
6 *
7 */
8
9 #include "fuse_main.h"
10
11 #include <dlfcn.h>
12 #include <unistd.h>
13
14 #include <cassert>
15 #include <cstdlib>
16 #include <cstring>
17 #include <string>
18 #include <vector>
19
20 #include "util/logging.h"
21 #include "util/platform.h"
22 #include "util/smalloc.h"
23 #include "util/string.h"
24
25 using namespace stub; // NOLINT
26
27
28 ✗ int main(int argc, char **argv) {
29 // Getopt option parsing modifies globals and the argv vector
30 ✗ const int opterr_save = opterr;
31 ✗ const int optc = argc;
32 ✗ assert(optc > 0);
33 ✗ char **optv = reinterpret_cast<char **>(smalloc(optc * sizeof(char *)));
34 ✗ for (int i = 0; i < optc; ++i) {
35 ✗ optv[i] = strdup(argv[i]);
36 }
37
38 ✗ bool debug = false;
39 int c;
40 ✗ opterr = 0;
41 ✗ while ((c = getopt(optc, optv, "do:")) != -1) {
42 ✗ switch (c) {
43 ✗ case 'd':
44 ✗ debug = true;
45 ✗ break;
46 ✗ case 'o':
47 ✗ std::vector<std::string> mount_options = SplitString(optarg, ',');
48 ✗ for (unsigned i = 0; i < mount_options.size(); ++i) {
49 ✗ if (mount_options[i] == "debug") {
50 ✗ debug = true;
51 }
52 }
53 ✗ break;
54 }
55 }
56 ✗ opterr = opterr_save;
57 ✗ optind = 1;
58 ✗ for (int i = 0; i < optc; ++i) {
59 ✗ free(optv[i]);
60 }
61 ✗ free(optv);
62
63 ✗ const std::string libname_fuse3 = platform_libname("cvmfs_fuse3_stub");
64
65 ✗ std::string error_messages;
66
67 ✗ std::string local_lib_path = "./";
68 ✗ if (getenv("CVMFS_LIBRARY_PATH") != NULL) {
69 ✗ local_lib_path = getenv("CVMFS_LIBRARY_PATH");
70 ✗ if (!local_lib_path.empty() && (*local_lib_path.rbegin() != '/'))
71 ✗ local_lib_path.push_back('/');
72 }
73
74 ✗ std::vector<std::string> library_paths;
75 ✗ library_paths.push_back(local_lib_path + libname_fuse3);
76 ✗ library_paths.push_back("/usr/lib/" + libname_fuse3);
77 ✗ library_paths.push_back("/usr/lib64/" + libname_fuse3);
78 #ifdef __APPLE__
79 // Since OS X El Capitan (10.11) came with SIP, we needed to relocate our
80 // binaries from /usr/... to /usr/local/...
81 library_paths.push_back("/usr/local/lib/" + libname_fuse3);
82 #endif
83
84 void *library_handle;
85 ✗ std::vector<std::string>::const_iterator i = library_paths.begin();
86 ✗ const std::vector<std::string>::const_iterator iend = library_paths.end();
87 ✗ for (; i != iend; ++i) {
88 ✗ library_handle = dlopen(i->c_str(), RTLD_NOW | RTLD_LOCAL);
89 ✗ if (library_handle != NULL) {
90 ✗ if (debug) {
91 ✗ LogCvmfs(kLogCvmfs, kLogDebug | kLogStdout, "Debug: using library %s",
92 i->c_str());
93 }
94 ✗ break;
95 }
96
97 ✗ error_messages += std::string(dlerror()) + "\n";
98 }
99
100 ✗ if (!library_handle) {
101 ✗ LogCvmfs(kLogCvmfs, kLogStderr | kLogSyslogErr,
102 "Error: failed to load cvmfs library, tried: '%s'\n%s",
103 JoinStrings(library_paths, "' '").c_str(), error_messages.c_str());
104 ✗ return 1;
105 }
106
107 CvmfsStubExports **exports_ptr = reinterpret_cast<CvmfsStubExports **>(
108 ✗ dlsym(library_handle, "g_cvmfs_stub_exports"));
109 ✗ if (exports_ptr == NULL) {
110 ✗ LogCvmfs(kLogCvmfs, kLogStderr | kLogSyslogErr,
111 "Error: symbol g_cvmfs_stub_exports not found");
112 ✗ return 1;
113 }
114
115 ✗ return (*exports_ptr)->fn_main(argc, argv);
116 }
117