38#include "blocxx/BLOCXX_config.h"
40#if !defined(BLOCXX_WIN32)
53#ifdef BLOCXX_HAVE_SYS_RESOURCE_H
54#include <sys/resource.h>
56#ifdef BLOCXX_HAVE_SYS_TYPES_H
59#ifdef BLOCXX_HAVE_UNISTD_H
75#if defined(sigemptyset)
85#define SIG_DFL (void(*)())0
96 Format
msg(
"Exec::spawn(%1): child startup failed: %2",
process_path, err.message);
97 if (err.error_num != 0)
100 ExecErrorException,
msg.c_str(), err.error_num);
112 Exec::PreExec::Error
x;
143 Format(
"Exec::spawn(%1): timed out waiting for child to exec()",
process_path).c_str());
146 Format(
"Exec::spawn(%1): error reading init status from child",
process_path).c_str(),
errnum);
180 char const *
const argv[],
char const *
const envp[],
188 Exec::PreExec::Error err;
190 err.message[0] =
'\0';
198 char *
const *
cc_argv =
const_cast<char *
const *
>(
argv);
199 char *
const *
cc_envp =
const_cast<char *
const *
>(
envp);
209 catch (Exec::PreExec::Error &
e)
213 catch (std::exception &
e)
218 catch (Exec::PreExec::DontCatch &
e)
309 for (
unsigned d = 0;
d < 3; ++
d)
356StandardPreExec::StandardPreExec() : PreExec(true)
367 std::vector<bool> empty;
368 PreExec::resetSignals();
369 PreExec::setNewProcessGroup();
370 PreExec::setupStandardDescriptors(
pparr);
371 PreExec::closeDescriptorsOnExec(empty);
387 std::vector<bool> empty;
388 PreExec::resetSignals();
389 PreExec::setNewProcessGroup();
390 PreExec::closeDescriptorsOnExec(empty);
#define BLOCXX_ASSERT(CON)
BLOCXX_ASSERT works similar to the assert() macro, but instead of calling abort(),...
#define BLOCXX_THROW(exType, msg)
Throw an exception using FILE and LINE.
#define BLOCXX_THROW_ERRNO_MSG1(exType, msg, errnum)
Throw an exception using FILE, LINE, errnum and strerror(errnum)
This class is used to specify what spawn() should do between fork and exec.
static void setupStandardDescriptors(pipe_pointer_t const pparr[])
For calling from PreExec::call.
static void resetSignals()
For calling from PreExec::call.
void closeDescriptorsOnExec(std::vector< bool > const &keep)
For calling from PreExec::call.
PreExec(bool precompute_max_descriptors=false)
static void setNewProcessGroup()
For calling from PreExec::call().
static void closePipesOnExec(pipe_pointer_t const pparr[])
For calling from PreExec::call.
virtual bool keepStd(int d) const
virtual void call(pipe_pointer_t const pparr[])
Resets all signals to their default actions and sets to close-on-exec all descriptors except the stan...
virtual bool keepStd(int d) const
virtual void call(pipe_pointer_t const pparr[])
Resets all signals to their default actions and sets to close-on-exec all descriptors except the stan...
Descriptor getInputHandle() const
Class for communicating with and managing a child process.
A timeout can be absolute, which means that it will happen at the specified DateTime.
static Timeout relative(float seconds)
Abstract interface for an UnnamedPipe.
static UnnamedPipeRef createUnnamedPipe(EOpen doOpen=E_OPEN)
Create an instance of the concrete class that implements the UnnamedPipe interface.
unsigned const BLOCXX_NPIPE
void close_child_ends(UnnamedPipeRef ppipe[BLOCXX_NPIPE])
unsigned const BLOCXX_EXEC_ERR
ProcessRef spawnImpl(char const *exec_path, char const *const argv[], char const *const envp[], Exec::PreExec &pre_exec)
char * strcpy_trunc(char *dst, std::size_t dstsize, char const *src)
PROMISE: copies the first n = min(strlen(src), dstsize - 1) characters of C-string src to dst,...
bool operator==(const Array< T > &x, const Array< T > &y)