23 #ifndef _PLUGINS_OPENPRS_UTILS_PROC_H_ 24 #define _PLUGINS_OPENPRS_UTILS_PROC_H_ 26 #include <logging/logger.h> 28 #include <boost/asio.hpp> 39 SubProcess(
const char *progname,
const char *file,
const char *argv[],
const char *envp[]);
46 const std::string & file,
47 const std::vector<std::string> &argv,
48 const std::vector<std::string> &envp);
50 const std::string & file,
51 const std::vector<std::string> &argv,
52 const std::vector<std::string> &envp,
77 return pipe_stdout_r_;
85 return pipe_stderr_r_;
90 boost::asio::posix::stream_descriptor &
98 boost::asio::posix::stream_descriptor &
106 boost::asio::posix::stream_descriptor &
112 void kill(
int signum);
119 pid_t run_proc(
const char *file,
126 void run_proc(
const char *file,
const char *argv[],
const char *envp[]);
128 void start_log(
const char * logname,
130 boost::asio::posix::stream_descriptor &sd,
131 boost::asio::streambuf & buf);
132 void handle_log_line(
const char * logname,
134 boost::asio::posix::stream_descriptor &sd,
135 boost::asio::streambuf & buf,
136 boost::system::error_code ec,
140 std::string progname_;
147 boost::asio::io_service io_service_;
148 std::thread io_service_thread_;
149 boost::asio::io_service::work io_service_work_;
153 boost::asio::posix::stream_descriptor sd_stdin_;
154 boost::asio::posix::stream_descriptor sd_stdout_;
155 boost::asio::posix::stream_descriptor sd_stderr_;
157 boost::asio::streambuf buf_stdout_;
158 boost::asio::streambuf buf_stderr_;
SubProcess(const char *progname, const char *file, const char *argv[], const char *envp[])
Constructor.
Fawkes library namespace.
boost::asio::posix::stream_descriptor & sd_stdout()
Get stdout stream descriptor.
int pipe_stdout_r() const
Get stdout pipe file descriptor.
void kill(int signum)
Send a signal to the process.
void check_proc()
Check if the process is still alive.
int pipe_stderr_r() const
Get stderr pipe file descriptor.
int pipe_stdin_w() const
Get stdin pipe file descriptor.
int exit_status()
Get exit status of process once it ended.
bool alive()
Check if process is alive.
boost::asio::posix::stream_descriptor & sd_stderr()
Get stderr stream descriptor.
pid_t pid() const
Get PID of sub-process.
Sub-process execution with stdin/stdout/stderr redirection.
boost::asio::posix::stream_descriptor & sd_stdin()
Get stdin stream descriptor.