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

Implementation of the external-tool helpers. More...

#include "postgres.h"
#include "provsql_utils.h"
#include "miscadmin.h"
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include "external_tool.h"
#include <string>
Include dependency graph for external_tool.cpp:

Go to the source code of this file.

Functions

int run_external_tool (const std::string &cmdline)
 Run a shell command line, optionally extending PATH.
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.

Variables

static const char * DEFAULT_PATH

Detailed Description

Implementation of the external-tool helpers.

Reads the provsql.tool_search_path GUC (exposed as provsql_tool_search_path) and uses it both to extend $PATH around system() and to drive the pre-flight find_external_tool() lookup.

Definition in file external_tool.cpp.

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 64 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 99 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, optionally extending PATH.

If provsql_tool_search_path is non-empty, it is prepended (with :) to $PATH before system() is called and restored afterwards.

Parameters
cmdlineShell command line, passed verbatim to /bin/sh -c.
Returns
The raw return value of system().

Definition at line 34 of file external_tool.cpp.

Here is the caller graph for this function:

Variable Documentation

◆ DEFAULT_PATH

const char* DEFAULT_PATH
static
Initial value:
=
"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

Definition at line 31 of file external_tool.cpp.