ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
external_tool.h File Reference

Helpers for invoking external command-line tools. More...

#include <string>
Include dependency graph for external_tool.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  provsql

Functions

int run_external_tool (const std::string &cmdline)
 Run a shell command line in its own process group, optionally extending PATH, interruptible by query cancel / statement_timeout.
std::string find_external_tool (const std::string &name)
 Locate an external tool by name.
std::string format_external_tool_status (int rv, const std::string &tool)
 Decode a system() return value into a human-readable message.
bool toolAvailable (const provsql::ToolRecord &rec)
 True iff a registry tool can currently be used.

Detailed Description

Helpers for invoking external command-line tools.

run_external_tool() runs a shell command line with the provsql.tool_search_path GUC, if set, prepended to $PATH for the duration of the call (the server's pre-existing PATH is restored afterwards). The command runs in its own process group so that a statement_timeout / pg_cancel_backend can stop it: on a pending cancel the whole group is SIGKILLed. Used by the d-DNNF compilers (d4, c2d, minic2d, dsharp), the model counters, and the graph-easy DOT renderer.

find_external_tool() walks the same locations and reports whether a given binary is present and executable, so callers can fail with an actionable error before composing a command line.

format_external_tool_status() decodes a system() return value into a human-readable message that distinguishes "tool not found" (shell exit 127), "tool not executable" (126), "killed by signal", and "ran and exited nonzero".

In the standalone tdkc build (when TDKC is defined) the GUC layer is unavailable; the helpers degenerate to a plain std::system() call and a no-op find_external_tool.

Definition in file external_tool.h.

Function Documentation

◆ find_external_tool()

std::string find_external_tool ( const std::string & name)

Locate an external tool by name.

Searches provsql_tool_search_path (colon-separated), then $PATH, for an executable file matching name (via access(X_OK)). Returns the full path on success, or the empty string if nothing matches.

Names containing a slash are treated as paths and tested directly without any directory walk.

Parameters
nameBare executable name (e.g. "d4") or a path.
Returns
Resolved path, or "" if name is not found.

Definition at line 150 of file external_tool.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ format_external_tool_status()

std::string format_external_tool_status ( int rv,
const std::string & tool )

Decode a system() return value into a human-readable message.

Parameters
rvReturn value from system() (or run_external_tool()).
toolTool name, used as the message subject.
Returns
Empty string when rv indicates success; otherwise a message that distinguishes "not found at runtime" (shell exit 127), "not executable" (126), "killed by signal N", "exited with status N", or system() itself failing.

Definition at line 197 of file external_tool.cpp.

Here is the caller graph for this function:

◆ run_external_tool()

int run_external_tool ( const std::string & cmdline)

Run a shell command line in its own process group, optionally extending PATH, interruptible by query cancel / statement_timeout.

If provsql_tool_search_path is non-empty, it is prepended (with :) to $PATH for the duration and restored afterwards. The command runs via /bin/sh -c as a process-group leader; while it runs the parent polls for a pending cancel/terminate and, if one fires, SIGKILLs the whole group (reaching tools that fork workers) and lets CHECK_FOR_INTERRUPTS raise it.

Parameters
cmdlineShell command line, passed verbatim to /bin/sh -c.
Returns
A wait(2) status (decode with WIFEXITED etc., as a system() return), or -1 if fork failed.

Definition at line 113 of file external_tool.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toolAvailable()

bool toolAvailable ( const provsql::ToolRecord & rec)

True iff a registry tool can currently be used.

A kcmcp record needs a configured endpoint (no live connect probe, mirroring how a CLI tool only needs its binary on PATH). A cli record needs its binary (when set) and every dependency to resolve on the backend's PATH via find_external_tool. This is the single availability predicate consulted both by the compile/wmc tool selection and by the provsql.tools view.

Definition at line 218 of file external_tool.cpp.

Here is the call graph for this function:
Here is the caller graph for this function: