yast2-core
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
ExternalProgram Class Reference

Execute a program and give access to its io An object of this class encapsulates the execution of an external program. It starts the program using fork and some exec.. call, gives you access to the program's stdio and closes the program after use. More...

#include <ExternalProgram.h>

Inheritance diagram for ExternalProgram:
ExternalDataSource Process

Public Types

enum  Stderr_Disposition { Normal_Stderr, Discard_Stderr, Stderr_To_Stdout, Stderr_To_FileDesc }
 
typedef std::map< std::string,
std::string > 
Environment
 

Public Member Functions

 ExternalProgram (std::string commandline, Stderr_Disposition stderr_disp=Normal_Stderr, bool use_pty=false, int stderr_fd=-1, bool default_locale=false, const Pathname &root="", bool pty_trans=true)
 
 ExternalProgram (const char *const *argv, Stderr_Disposition stderr_disp=Normal_Stderr, bool use_pty=false, int stderr_fd=-1, bool default_locale=false, const Pathname &root="", bool pty_trans=true)
 
 ExternalProgram (const char *const *argv, const Environment &environment, Stderr_Disposition stderr_disp=Normal_Stderr, bool use_pty=false, int stderr_fd=-1, bool default_locale=false, const Pathname &root="", bool pty_trans=true)
 
 ExternalProgram (const char *binpath, const char *const *argv_1, bool use_pty=false, bool pty_trans=true)
 
 ExternalProgram (const char *binpath, const char *const *argv_1, const Environment &environment, bool use_pty=false, bool pty_trans=true)
 
 ~ExternalProgram ()
 
int close ()
 
bool kill ()
 
bool running ()
 
pid_t getpid ()
 
- Public Member Functions inherited from ExternalDataSource
 ExternalDataSource (FILE *inputfile=0, FILE *outputfile=0)
 
virtual ~ExternalDataSource ()
 
bool send (const char *buffer, size_t length)
 
bool send (std::string s)
 
size_t receive (char *buffer, size_t length)
 
std::string receiveLine ()
 
std::string receiveUpto (char c)
 
void setBlocking (bool mode)
 
FILE * inputFile () const
 
FILE * outputFile () const
 

Static Public Member Functions

static void renumber_fd (int origfd, int newfd)
 

Protected Member Functions

int checkStatus (int)
 

Private Member Functions

void start_program (const char *const *argv, const Environment &environment, Stderr_Disposition stderr_disp=Normal_Stderr, int stderr_fd=-1, bool default_locale=false, const char *root=NULL)
 
bool disableCRLFTranslation (int fd)
 

Private Attributes

bool use_pty
 
bool disable_pty_trans
 
pid_t pid
 
int _exitStatus
 

Additional Inherited Members

- Protected Attributes inherited from ExternalDataSource
FILE * inputfile
 
FILE * outputfile
 

Detailed Description

Execute a program and give access to its io An object of this class encapsulates the execution of an external program. It starts the program using fork and some exec.. call, gives you access to the program's stdio and closes the program after use.

Member Typedef Documentation

typedef std::map<std::string,std::string> ExternalProgram::Environment

For passing additional environment variables to set

Member Enumeration Documentation

Define symbols for different policies on the handling of stderr

Enumerator
Normal_Stderr 
Discard_Stderr 
Stderr_To_Stdout 
Stderr_To_FileDesc 

Constructor & Destructor Documentation

ExternalProgram::ExternalProgram ( std::string  commandline,
Stderr_Disposition  stderr_disp = Normal_Stderr,
bool  use_pty = false,
int  stderr_fd = -1,
bool  default_locale = false,
const Pathname root = "",
bool  pty_trans = true 
)

Start the external program by using the shell /bin/sh with the option -c. You can use io direction symbols < and >.

Parameters
commandlinea shell commandline that is appended to /bin/sh -c.
default_localewhether to set LC_ALL=C before starting
rootdirectory to chroot into, / or empty to not chroot

References Pathname::asString(), Pathname::empty(), and start_program().

ExternalProgram::ExternalProgram ( const char *const *  argv,
Stderr_Disposition  stderr_disp = Normal_Stderr,
bool  use_pty = false,
int  stderr_fd = -1,
bool  default_locale = false,
const Pathname root = "",
bool  pty_trans = true 
)

Start an external program by giving the arguments as an arry of char *pointers. If environment is provided, varaiables will be added to the childs environment, overwriting existing ones.

References Pathname::asString(), Pathname::empty(), and start_program().

ExternalProgram::ExternalProgram ( const char *const *  argv,
const Environment environment,
Stderr_Disposition  stderr_disp = Normal_Stderr,
bool  use_pty = false,
int  stderr_fd = -1,
bool  default_locale = false,
const Pathname root = "",
bool  pty_trans = true 
)
ExternalProgram::ExternalProgram ( const char *  binpath,
const char *const *  argv_1,
bool  use_pty = false,
bool  pty_trans = true 
)

References start_program().

ExternalProgram::ExternalProgram ( const char *  binpath,
const char *const *  argv_1,
const Environment environment,
bool  use_pty = false,
bool  pty_trans = true 
)

References start_program().

ExternalProgram::~ExternalProgram ( )

Member Function Documentation

int ExternalProgram::checkStatus ( int  status)
protected

References D__, DBG, ERR, pid, and WAR.

Referenced by close(), and running().

int ExternalProgram::close ( )
virtual
bool ExternalProgram::disableCRLFTranslation ( int  fd)
private

References ERR.

Referenced by start_program().

pid_t ExternalProgram::getpid ( )
inline

return pid

References pid.

Referenced by Process::kill(), and Process::~Process().

bool ExternalProgram::kill ( )

Kill the program

References close(), and pid.

Referenced by Process::kill().

void ExternalProgram::renumber_fd ( int  origfd,
int  newfd 
)
static

origfd will be accessible as newfd and closed (unless they were equal)

References close().

Referenced by Y2ProgramComponent::launchExternalProgram(), shellcommand(), and start_program().

bool ExternalProgram::running ( )

Return whether program is running

References _exitStatus, checkStatus(), and pid.

Referenced by Process::~Process().

void ExternalProgram::start_program ( const char *const *  argv,
const Environment environment,
Stderr_Disposition  stderr_disp = Normal_Stderr,
int  stderr_fd = -1,
bool  default_locale = false,
const char *  root = NULL 
)
private

Member Data Documentation

int ExternalProgram::_exitStatus
private

Referenced by close(), running(), and start_program().

bool ExternalProgram::disable_pty_trans
private

Set to true if LF to CRLF output tranformation on the pty will be disabled

Referenced by start_program().

pid_t ExternalProgram::pid
private
bool ExternalProgram::use_pty
private

Set to true, if a pair of ttys is used for communication instead of a pair of pipes.

Referenced by start_program().


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

Generated on a sunny day for yast2-core by doxygen 1.8.8