MCPcopy Create free account
hub / github.com/apache/trafficserver / path_handler

Function path_handler

src/traffic_layout/engine.cc:97–153  ·  view source on GitHub ↗

handle the path of the engine during parsing

Source from the content-addressed store, hash-verified

95
96// handle the path of the engine during parsing
97static std::string
98path_handler(const std::string &path, bool run_flag, const std::string &command)
99{
100 std::string cur_working_dir = "";
101 char cwd[PATH_MAX];
102 if (!getcwd(cwd, sizeof(cwd))) {
103 ink_warning("unexpected failure from getcwd() - %s", strerror(errno));
104 } else {
105 cur_working_dir = cwd;
106 }
107
108 if (run_flag) {
109 // no path passed in, use cwd
110 if (path.empty()) {
111 return cur_working_dir;
112 }
113 if (path[0] == '/') {
114 return path;
115 } else {
116 return Layout::relative_to(cur_working_dir, path);
117 }
118 }
119
120 // for other commands
121 // 1. passed in path
122 if (!path.empty()) {
123 std::string cmdpath;
124 if (path[0] == '/') {
125 cmdpath = check_path(path);
126 } else {
127 cmdpath = check_path(Layout::relative_to(cur_working_dir, path));
128 }
129 if (!cmdpath.empty()) {
130 return cmdpath;
131 }
132 }
133
134 // 2. find cwd or parent path of cwd to check
135 std::string cwdpath = check_parent_path(cur_working_dir);
136 if (!cwdpath.empty()) {
137 return cwdpath;
138 }
139
140 // 3. installed executable
141 char RealBinPath[PATH_MAX] = {0};
142 if (!command.empty() && realpath(command.c_str(), RealBinPath) != nullptr) {
143 std::string bindir = RealBinPath;
144
145 bindir = bindir.substr(0, bindir.find_last_of("/")); // getting the bin dir not executable path
146 bindir = check_parent_path(bindir);
147 if (!bindir.empty()) {
148 return bindir;
149 }
150 }
151
152 return path;
153}
154

Callers 3

create_runrootMethod · 0.85
remove_runrootMethod · 0.85
verify_runrootMethod · 0.85

Calls 6

ink_warningFunction · 0.85
check_pathFunction · 0.85
check_parent_pathFunction · 0.85
emptyMethod · 0.45
c_strMethod · 0.45
substrMethod · 0.45

Tested by

no test coverage detected