27#include <unordered_map>
37 "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
59#ifdef PROVSQL_NO_SUBPROCESS
78 execl(
"/bin/sh",
"sh",
"-c", cmdline.c_str(), (
char *) NULL);
83 setpgid(child, child);
87 pid_t w = waitpid(child, &status, WNOHANG);
90 if (w < 0 && errno != EINTR) {
101 if (QueryCancelPending || ProcDiePending) {
102 killpg(child, SIGKILL);
104 do { r = waitpid(child, &status, 0); }
while (r < 0 && errno == EINTR);
116 std::string saved_path;
117 bool had_path =
false;
120 const char *cur = getenv(
"PATH");
128 setenv(
"PATH", new_path.c_str(), 1);
135 setenv(
"PATH", saved_path.c_str(), 1);
145 CHECK_FOR_INTERRUPTS();
153 if (name.find(
'/') != std::string::npos)
154 return access(name.c_str(), X_OK) == 0 ? name :
"";
167 static std::unordered_map<std::string, std::string> tool_cache;
171 auto cached = tool_cache.find(key);
172 if (cached != tool_cache.end())
173 return cached->second;
184 std::string check =
"command -v '" + name +
"' >/dev/null 2>&1";
191 tool_cache[key] = name;
201 return tool +
" could not be invoked (system() returned -1)";
203 return tool +
" terminated by signal "
204 + std::to_string(WTERMSIG(rv));
206 int code = WEXITSTATUS(rv);
208 return tool +
" was not found at runtime (shell exit 127); "
209 "install it or add its directory to provsql.tool_search_path";
211 return tool +
" is not executable (shell exit 126); "
212 "check permissions on the binary";
213 return tool +
" exited with status " + std::to_string(code);
215 return tool +
" failed with raw status " + std::to_string(rv);
219 if (rec.
kind ==
"kcmcp")
char * provsql_tool_search_path
Colon-separated directory list prepended to PATH when invoking external tools (d4,...
Build-configuration switches shared across the C and C++ sources.
Core types, constants, and utilities shared across ProvSQL.