Fawkes API  Fawkes Development Version
fawkes::SubProcess Class Reference

Sub-process execution with stdin/stdout/stderr redirection. More...

#include <>>

Public Member Functions

 SubProcess (const char *progname, const char *file, const char *argv[], const char *envp[])
 Constructor. More...
 
 SubProcess (const char *progname, const char *file, const char *argv[], const char *envp[], fawkes::Logger *logger)
 Constructor. More...
 
 ~SubProcess ()
 Destructor. More...
 
pid_t pid () const
 Get PID of sub-process. More...
 
int pipe_stdin_w () const
 Get stdin pipe file descriptor. More...
 
int pipe_stdout_r () const
 Get stdout pipe file descriptor. More...
 
int pipe_stderr_r () const
 Get stderr pipe file descriptor. More...
 
boost::asio::posix::stream_descriptor & sd_stdin ()
 Get stdin stream descriptor. More...
 
boost::asio::posix::stream_descriptor & sd_stdout ()
 Get stdout stream descriptor. More...
 
boost::asio::posix::stream_descriptor & sd_stderr ()
 Get stderr stream descriptor. More...
 
void kill (int signum)
 Send a signal to the process. More...
 
void check_proc ()
 Check if the process is still alive. More...
 

Detailed Description

Sub-process execution with stdin/stdout/stderr redirection.

This class executes a sub-process and monitors it and supports redirecting stdout/stderr to a logger.

Author
Tim Niemueller

Definition at line 39 of file proc.h.

Constructor & Destructor Documentation

◆ SubProcess() [1/2]

fawkes::SubProcess::SubProcess ( const char *  progname,
const char *  file,
const char *  argv[],
const char *  envp[] 
)

Constructor.

Parameters
prognamename of program, component name for logging
filefile to execute, can be a program in the path or a fully qualified path
argvarray of arguments for the process, the last element must be NULL
envparray of environment variables for the process, the last element must be NULL. Can be NULL to omit.

Definition at line 56 of file proc.cpp.

◆ SubProcess() [2/2]

fawkes::SubProcess::SubProcess ( const char *  progname,
const char *  file,
const char *  argv[],
const char *  envp[],
fawkes::Logger logger 
)

Constructor.

Parameters
prognamename of program, component name for logging
filefile to execute, can be a program in the path or a fully qualified path
argvarray of arguments for the process, the last element must be NULL
envparray of environment variables for the process, the last element must be NULL. Can be NULL to omit.
loggerlogger to redirect stdout and stderr to

Definition at line 76 of file proc.cpp.

◆ ~SubProcess()

fawkes::SubProcess::~SubProcess ( )

Destructor.

Definition at line 88 of file proc.cpp.

References kill().

Member Function Documentation

◆ check_proc()

void fawkes::SubProcess::check_proc ( )

Check if the process is still alive.

Definition at line 240 of file proc.cpp.

References fawkes::Logger::log_error(), and fawkes::Logger::log_warn().

Referenced by OpenPRSThread::loop(), and sd_stderr().

◆ kill()

void fawkes::SubProcess::kill ( int  signum)

Send a signal to the process.

Parameters
signumsignal number

Definition at line 100 of file proc.cpp.

References fawkes::Logger::LL_INFO, fawkes::Logger::LL_WARN, fawkes::Logger::log(), fawkes::Logger::log_error(), pid(), pipe_stderr_r(), pipe_stdin_w(), and pipe_stdout_r().

Referenced by OpenPRSThread::finalize(), sd_stderr(), and ~SubProcess().

◆ pid()

pid_t fawkes::SubProcess::pid ( ) const
inline

Get PID of sub-process.

Returns
process ID of sub-process.

Definition at line 49 of file proc.h.

Referenced by kill().

◆ pipe_stderr_r()

int fawkes::SubProcess::pipe_stderr_r ( ) const
inline

Get stderr pipe file descriptor.

Returns
stderr pipe file descriptor, only valid for reading.

Definition at line 64 of file proc.h.

Referenced by kill(), and sd_stderr().

◆ pipe_stdin_w()

int fawkes::SubProcess::pipe_stdin_w ( ) const
inline

Get stdin pipe file descriptor.

Returns
stdin pipe file descriptor, only valid for writing.

Definition at line 54 of file proc.h.

Referenced by kill(), and sd_stderr().

◆ pipe_stdout_r()

int fawkes::SubProcess::pipe_stdout_r ( ) const
inline

Get stdout pipe file descriptor.

Returns
stdout pipe file descriptor, only valid for reading.

Definition at line 59 of file proc.h.

Referenced by kill(), and sd_stderr().

◆ sd_stderr()

boost::asio::posix::stream_descriptor& fawkes::SubProcess::sd_stderr ( )
inline

Get stderr stream descriptor.

Returns
stderr stream descriptor, only valid for reading.

Definition at line 79 of file proc.h.

References check_proc(), kill(), pipe_stderr_r(), pipe_stdin_w(), and pipe_stdout_r().

◆ sd_stdin()

boost::asio::posix::stream_descriptor& fawkes::SubProcess::sd_stdin ( )
inline

Get stdin stream descriptor.

Returns
stdin stream descriptor, only valid for writing.

Definition at line 69 of file proc.h.

◆ sd_stdout()

boost::asio::posix::stream_descriptor& fawkes::SubProcess::sd_stdout ( )
inline

Get stdout stream descriptor.

Returns
stdout stream descriptor, only valid for reading.

Definition at line 74 of file proc.h.


The documentation for this class was generated from the following files: