zypp::ExternalProgram Class Reference

Execute a program and give access to its io An object of this class encapsulates the execution of an external program. More...

#include <ExternalProgram.h>

Inheritance diagram for zypp::ExternalProgram:

zypp::externalprogram::ExternalDataSource List of all members.

Public Types

typedef std::map< std::string,
std::string > 
Environment
 For passing additional environment variables to set.
enum  Stderr_Disposition { Normal_Stderr, Discard_Stderr, Stderr_To_Stdout, Stderr_To_FileDesc }
 Define symbols for different policies on the handling of stderr. More...

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="")
 Start the external program by using the shell /bin/sh with the option -c.
 ExternalProgram ()
 Start an external program by giving the arguments as an arry of char *pointers.
 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="")
 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="")
 ExternalProgram (const char *binpath, const char *const *argv_1, bool use_pty=false)
 ExternalProgram (const char *binpath, const char *const *argv_1, const Environment &environment, bool use_pty=false)
 ~ExternalProgram ()
int close ()
 Close the input and output streams.
bool kill ()
 Kill the program.
bool running ()
 Return whether program is running.
pid_t getpid ()
 return pid

Static Public Member Functions

static void renumber_fd (int origfd, int newfd)
 origfd will be accessible as newfd and closed (unless they were equal)

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)

Private Attributes

bool use_pty
 Set to true, if a pair of ttys is used for communication instead of a pair of pipes.
pid_t pid
int _exitStatus

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.

Definition at line 34 of file ExternalProgram.h.


Member Typedef Documentation

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

For passing additional environment variables to set.

Definition at line 52 of file ExternalProgram.h.


Member Enumeration Documentation

enum zypp::ExternalProgram::Stderr_Disposition
 

Define symbols for different policies on the handling of stderr.

Enumerator:
Normal_Stderr 
Discard_Stderr 
Stderr_To_Stdout 
Stderr_To_FileDesc 

Definition at line 42 of file ExternalProgram.h.


Constructor & Destructor Documentation

zypp::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 = ""
 

Start the external program by using the shell /bin/sh with the option -c.

You can use io direction symbols < and >.

Parameters:
commandline a shell commandline that is appended to /bin/sh -c.
default_locale whether to set LC_ALL=C before starting
root directory to chroot into, / or empty to not chroot

zypp::ExternalProgram::ExternalProgram  ) 
 

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.

Definition at line 36 of file ExternalProgram.cc.

zypp::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 = ""
 

Definition at line 62 of file ExternalProgram.cc.

References zypp::filesystem::Pathname::asString(), and zypp::filesystem::Pathname::empty().

zypp::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 = ""
 

Definition at line 78 of file ExternalProgram.cc.

References zypp::filesystem::Pathname::asString(), and zypp::filesystem::Pathname::empty().

zypp::ExternalProgram::ExternalProgram const char *  binpath,
const char *const *  argv_1,
bool  use_pty = false
 

Definition at line 93 of file ExternalProgram.cc.

References start_program().

zypp::ExternalProgram::ExternalProgram const char *  binpath,
const char *const *  argv_1,
const Environment environment,
bool  use_pty = false
 

Definition at line 108 of file ExternalProgram.cc.

References start_program().

zypp::ExternalProgram::~ExternalProgram  ) 
 

Definition at line 122 of file ExternalProgram.cc.


Member Function Documentation

int zypp::ExternalProgram::close  )  [virtual]
 

Close the input and output streams.

Reimplemented from zypp::externalprogram::ExternalDataSource.

Definition at line 292 of file ExternalProgram.cc.

References _exitStatus, checkStatus(), and pid.

Referenced by zypp::KeyRing::Impl::deleteKey(), zypp::debug::dumpMemOn(), zypp::KeyRing::Impl::importKey(), zypp::storage::XMLFilesBackend::isBackendInitialized(), kill(), renumber_fd(), zypp::media::Mount::Status(), zypp::target::rpm::RpmDb::systemStatus(), and zypp::KeyRing::Impl::verifyFile().

bool zypp::ExternalProgram::kill  ) 
 

Kill the program.

Definition at line 356 of file ExternalProgram.cc.

References close(), and pid.

Referenced by zypp::media::Mount::Kill(), zypp::media::Mount::Status(), zypp::target::rpm::RpmDb::systemKill(), and zypp::target::rpm::RpmDb::systemStatus().

bool zypp::ExternalProgram::running  ) 
 

Return whether program is running.

Definition at line 368 of file ExternalProgram.cc.

References _exitStatus, checkStatus(), ERR, pid, and zypp::str::strerror().

pid_t zypp::ExternalProgram::getpid  )  [inline]
 

return pid

Definition at line 110 of file ExternalProgram.h.

References pid.

Referenced by zypp::target::rpm::RpmDb::doRebuildDatabase().

void zypp::ExternalProgram::renumber_fd int  origfd,
int  newfd
[static]
 

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

Definition at line 392 of file ExternalProgram.cc.

References close().

int zypp::ExternalProgram::checkStatus int   )  [protected]
 

Definition at line 320 of file ExternalProgram.cc.

References DBG, ERR, pid, and WAR.

Referenced by close(), and running().

void zypp::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]
 

Definition at line 128 of file ExternalProgram.cc.

References _exitStatus, DBG, ERR, pid, and use_pty.

Referenced by ExternalProgram().


Member Data Documentation

bool zypp::ExternalProgram::use_pty [private]
 

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

Definition at line 126 of file ExternalProgram.h.

Referenced by start_program().

pid_t zypp::ExternalProgram::pid [private]
 

Definition at line 128 of file ExternalProgram.h.

Referenced by checkStatus(), close(), getpid(), kill(), running(), and start_program().

int zypp::ExternalProgram::_exitStatus [private]
 

Definition at line 129 of file ExternalProgram.h.

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


The documentation for this class was generated from the following files:
Generated on Thu Jul 6 00:07:30 2006 for zypp by  doxygen 1.4.6