zypp::ExternalProgram Class Reference

#include <ExternalProgram.h>

Inheritance diagram for zypp::ExternalProgram:
[legend]

List of all members.

Public Types

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

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 31 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 49 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 39 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

Definition at line 38 of file ExternalProgram.cc.

References start_program().

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 33 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 start_program().

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 80 of file ExternalProgram.cc.

References start_program().

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

Definition at line 95 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 110 of file ExternalProgram.cc.

References start_program().

zypp::ExternalProgram::~ExternalProgram (  ) 

Definition at line 124 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 295 of file ExternalProgram.cc.

References _exitStatus, checkStatus(), and pid.

Referenced by zypp::applydeltarpm::applydeltarpm(), zypp::filesystem::clean_dir(), zypp::filesystem::copy(), zypp::filesystem::copy_dir(), zypp::filesystem::copy_dir_content(), zypp::filesystem::copy_file2dir(), zypp::KeyRing::Impl::deleteKey(), zypp::target::rpm::diffFiles(), zypp::debug::dumpMemOn(), zypp::KeyRing::Impl::dumpPublicKey(), zypp::KeyRing::Impl::importKey(), zypp::storage::XMLFilesBackend::isBackendInitialized(), kill(), zypp::media::MediaCD::openTray(), zypp::KeyRing::Impl::publicKeyIds(), zypp::PublicKey::Impl::readFromFile(), zypp::KeyRing::Impl::readSignatureKeyId(), renumber_fd(), start_program(), zypp::media::Mount::Status(), zypp::target::rpm::RpmDb::systemStatus(), zypp::KeyRing::Impl::verifyFile(), and zypp::media::MediaDISK::verifyIfDiskVolume().

bool zypp::ExternalProgram::kill (  ) 

Kill the program.

Definition at line 359 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 371 of file ExternalProgram.cc.

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

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

return pid

Definition at line 107 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 395 of file ExternalProgram.cc.

References close().

Referenced by start_program().

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

Definition at line 323 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 130 of file ExternalProgram.cc.

References _exitStatus, close(), DBG, Discard_Stderr, ERR, zypp::externalprogram::ExternalDataSource::inputfile, name, zypp::externalprogram::ExternalDataSource::outputfile, pid, renumber_fd(), Stderr_To_FileDesc, Stderr_To_Stdout, zypp::str::strerror(), 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 123 of file ExternalProgram.h.

Referenced by start_program().

pid_t zypp::ExternalProgram::pid [private]

Definition at line 125 of file ExternalProgram.h.

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

int zypp::ExternalProgram::_exitStatus [private]

Definition at line 126 of file ExternalProgram.h.

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


The documentation for this class was generated from the following files:
Generated on Tue Sep 25 19:23:14 2007 for libzypp by  doxygen 1.5.3