32#ifndef ASYNC_EXEC_INCLUDED
33#define ASYNC_EXEC_INCLUDED
44#include <sigc++/sigc++.h>
131class Exec :
public sigc::trackable
134 using Environment = std::vector<std::pair<std::string,std::string>>;
139 explicit Exec(
const std::string &cmdline=
"");
161 const std::string &
command(
void)
const {
return args[0]; }
348 typedef std::map<pid_t, Exec*> ExecMap;
350 static ExecMap execs;
351 static int sigchld_pipe[2];
353 static struct sigaction old_sigact;
355 std::vector<std::string> args;
356 std::vector<std::string> env;
365 bool clear_env =
false;
367 static void handleSigChld(
int signal_number, siginfo_t *info,
369 static void sigchldReceived(
void);
375 void subprocessExited(
void);
376 void handleTimeout(
void);
Contains a watch for file descriptors.
Execute external commands.
void addEnvironmentVar(const std::string &name, const std::string &val)
Add an additional environment variable.
sigc::signal< void, const char *, int > stderrData
A signal that is emitted when the subprocess write to stderr.
void addEnvironmentVars(const Environment &env)
Add multiple environment variables.
sigc::signal< void > stdoutClosed
A signal that is emitted when the subprocess close its stdout.
bool closeStdin(void)
Close the stdin pipe to the subprocess.
bool writeStdin(const std::string &str)
Write data to stdin on the subprocess.
int exitStatus(void) const
Read the exit code of the subprocess.
bool kill(int sig=SIGTERM)
Send a UNIX signal to the subprocess.
const std::string & command(void) const
Get the command name for the command.
void setTimeout(int time_s)
Set a timeout on the allowed runtime for the subprocess.
Exec(const std::string &cmdline="")
Default constructor.
bool ifExited(void) const
Check if the subprocess exited in a normal way.
void clearEnvironment(void)
Clear the environment.
bool run(void)
Run the command.
int termSig(void) const
Read the UNIX signal number that caused the subprocess to stop.
void appendArgument(const std::string &arg)
Append a command line argument to a command.
sigc::signal< void > exited
A signal that is emitted when the subprocess exits.
bool writeStdin(const char *buf, int cnt)
Write data to stdin on the subprocess.
bool ifSignaled(void) const
Check if the subprocess exited due to receiving a UNIX signal.
void setCommandLine(const std::string &cmdline)
Set the command line to use.
bool nice(int inc=10)
Modify the nice value for the child subprocess.
sigc::signal< void > stderrClosed
A signal that is emitted when the subprocess close its stderr.
sigc::signal< void, const char *, int > stdoutData
A signal that is emitted when the subprocess write to stdout.
std::vector< std::pair< std::string, std::string > > Environment
A class for watching file descriptors.
A class that produces timer events.
Namespace for the asynchronous programming classes.