31#include <unordered_map>
41 "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
86#ifdef PROVSQL_NO_SUBPROCESS
105 execl(
"/bin/sh",
"sh",
"-c", cmdline.c_str(), (
char *) NULL);
110 setpgid(child, child);
114 const auto started = std::chrono::steady_clock::now();
116 pid_t w = waitpid(child, &status, WNOHANG);
119 if (w < 0 && errno != EINTR) {
130 if (QueryCancelPending || ProcDiePending) {
131 killpg(child, SIGKILL);
133 do { r = waitpid(child, &status, 0); }
while (r < 0 && errno == EINTR);
143 killpg(child, SIGKILL);
145 do { r = waitpid(child, &status, 0); }
while (r < 0 && errno == EINTR);
152 std::chrono::duration<double, std::milli>(
153 std::chrono::steady_clock::now() - started).count()
155 killpg(child, SIGKILL);
157 do { r = waitpid(child, &status, 0); }
while (r < 0 && errno == EINTR);
170 std::string saved_path;
171 bool had_path =
false;
174 const char *cur = getenv(
"PATH");
182 setenv(
"PATH", new_path.c_str(), 1);
191 setenv(
"PATH", saved_path.c_str(), 1);
201 CHECK_FOR_INTERRUPTS();
207 (
"an external tool took the evaluation past provsql.max_memory (" +
209 "Raise provsql.max_memory (e.g., SET provsql.max_memory = '2GB'), or "
210 "set it to 0 for no limit.");
216 "an external tool was stopped after " +
218 " ms, the time the cheapest alternative was expected to take");
227 if (name.find(
'/') != std::string::npos)
228 return access(name.c_str(), X_OK) == 0 ? name :
"";
241 static std::unordered_map<std::string, std::string> tool_cache;
245 auto cached = tool_cache.find(key);
246 if (cached != tool_cache.end())
247 return cached->second;
258 std::string check =
"command -v '" + name +
"' >/dev/null 2>&1";
265 tool_cache[key] = name;
275 return tool +
" could not be invoked (system() returned -1)";
277 return tool +
" terminated by signal "
278 + std::to_string(WTERMSIG(rv));
280 int code = WEXITSTATUS(rv);
282 return tool +
" was not found at runtime (shell exit 127); "
283 "install it or add its directory to provsql.tool_search_path";
285 return tool +
" is not executable (shell exit 126); "
286 "check permissions on the binary";
287 return tool +
" exited with status " + std::to_string(code);
289 return tool +
" failed with raw status " + std::to_string(rv);
293 if (rec.
kind ==
"kcmcp")
Generic directed-acyclic-graph circuit template and gate identifier.
std::size_t provsql_process_group_rss(pid_t pgid)
The resident memory of the processes of group pgid, in bytes, or 0 where the platform does not say.
Resident memory of a process, or of a process group.
char * provsql_tool_search_path
Colon-separated directory list prepended to PATH when invoking external tools (d4,...
int provsql_max_memory
Memory, in MB, that the evaluations of a statement may add to the backend's resident set,...
Build-configuration switches shared across the C and C++ sources.
void provsql_limit_exceeded(const char *tag, const char *message, const char *hint)
Stop the evaluation at a resource limit (provsql.max_memory, provsql.max_worlds): throws,...
size_t provsql_memory_used(void)
How much the backend's resident memory has grown since the first evaluation of the statement,...
Cancellation of the long C++ evaluation loops.
Core types, constants, and utilities shared across ProvSQL.