sbuild  1.6.10
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
sbuild::run_parts Class Reference

Run all scripts or programs within a directory. More...

#include <sbuild-run-parts.h>

+ Collaboration diagram for sbuild::run_parts:

Public Types

enum  error_code {
  CHILD_FORK, CHILD_WAIT, EXEC, PIPE,
  DUP, POLL, READ
}
 Error codes. More...
 
typedef custom_error< error_codeerror
 Exception type.
 

Public Member Functions

 run_parts (std::string const &directory, bool lsb_mode=true, bool abort_on_error=true, mode_t umask=022)
 The constructor. More...
 
 ~run_parts ()
 The destructor.
 
bool get_verbose () const
 Get the verbosity level. More...
 
void set_verbose (bool verbose)
 Set the verbosity level. More...
 
bool get_reverse () const
 Get the script execution order. More...
 
void set_reverse (bool reverse)
 Set the script execution order. More...
 
int run (string_list const &command, environment const &env)
 Run all scripts in the specified directory. More...
 

Private Types

typedef std::set< std::string > program_set
 A sorted set of filenames to use.
 

Private Member Functions

int run_child (std::string const &file, string_list const &command, environment const &env)
 Run the command specified by file (an absolute pathname), using command and env as the argv and environment, respectively. More...
 
void wait_for_child (pid_t pid, int &child_status)
 Wait for a child process to complete, and check its exit status. More...
 

Private Attributes

bool lsb_mode
 The LSB mode for allowed filenames.
 
bool abort_on_error
 Whether to abort on script execution error.
 
mode_t umask
 The umask to run scripts with.
 
bool verbose
 Verbose logging.
 
bool reverse
 Execute scripts in reverse order.
 
std::string directory
 The directory to run scripts from.
 
program_set programs
 The list of scripts to run.
 

Friends

template<class charT , class traits >
std::basic_ostream< charT, traits > & operator<< (std::basic_ostream< charT, traits > &stream, run_parts const &rhs)
 Output the environment to an ostream. More...
 

Detailed Description

Run all scripts or programs within a directory.

Member Enumeration Documentation

Error codes.

Enumerator
CHILD_FORK 

Failed to fork child.

CHILD_WAIT 

Wait for child failed.

EXEC 

Failed to execute.

PIPE 

Failed to create pipe.

DUP 

Failed to duplicate file descriptor.

POLL 

Failed to poll file descriptor.

READ 

Failed to read file descriptor.

Constructor & Destructor Documentation

run_parts::run_parts ( std::string const &  directory,
bool  lsb_mode = true,
bool  abort_on_error = true,
mode_t  umask = 022 
)

The constructor.

Parameters
directorythe directory to run scripts from.
lsb_modeuse Linux Standard Base filename requirements. If true, the following patterns are permitted: LANANA ("^[a-z0-9]+$"), LSB ("^_?([a-z0-9_.]+-)+[a-z0-9]+$"), and Debian cron ("^[a-z0-9][a-z0-9-]*$"). Debian dpkg conffile backups are not permitted ("dpkg-(old|dist|new|tmp)$"). If false, the traditional run-parts pattern is used ("^[a-zA-Z0-9_-]$").
abort_on_errorstop executing scripts if one returns an error.
umaskthe umask to set when running scripts.

References sbuild::is_valid_filename(), and programs.

Member Function Documentation

bool run_parts::get_reverse ( ) const

Get the script execution order.

Returns
true if executing in reverse, otherwise false.

References reverse.

bool run_parts::get_verbose ( ) const

Get the verbosity level.

Returns
true if verbose, otherwise false.

References verbose.

int run_parts::run ( string_list const &  command,
environment const &  env 
)

Run all scripts in the specified directory.

If abort_on_error is true, execution will stop at the first script to fail.

Parameters
commandthe command to run.
envthe environment to use.
Returns
the exit status of the scripts. This will be 0 on success, or the exit status of the last failing script.

References abort_on_error, programs, reverse, and run_child().

Referenced by sbuild::session::setup_chroot().

+ Here is the caller graph for this function:

int run_parts::run_child ( std::string const &  file,
string_list const &  command,
environment const &  env 
)
private

Run the command specified by file (an absolute pathname), using command and env as the argv and environment, respectively.

Parameters
filethe program to execute.
commandthe arguments to pass to the executable.
envthe environment.
Returns
the return value of the execve system call on failure.

References sbuild::_(), CHILD_FORK, sbuild::DEBUG_INFO, directory, DUP, EXEC, sbuild::exec(), sbuild::log_debug(), sbuild::log_error(), sbuild::log_exception_error(), sbuild::log_info(), PIPE, POLL, READ, sbuild::split_string_strict(), sbuild::string_list_to_string(), umask, verbose, and wait_for_child().

Referenced by run().

+ Here is the caller graph for this function:

void run_parts::set_reverse ( bool  reverse)

Set the script execution order.

Parameters
reversetrue to execute in reverse, otherwise false.

References reverse.

Referenced by sbuild::session::setup_chroot().

+ Here is the caller graph for this function:

void run_parts::set_verbose ( bool  verbose)

Set the verbosity level.

Parameters
verbosetrue to be verbose, otherwise false.

References verbose.

Referenced by sbuild::session::setup_chroot().

+ Here is the caller graph for this function:

void run_parts::wait_for_child ( pid_t  pid,
int &  child_status 
)
private

Wait for a child process to complete, and check its exit status.

An error will be thrown on failure.

Parameters
pidthe pid to wait for.
child_statusthe place to store the child exit status.

References CHILD_WAIT.

Referenced by run_child().

+ Here is the caller graph for this function:

Friends And Related Function Documentation

template<class charT , class traits >
std::basic_ostream<charT,traits>& operator<< ( std::basic_ostream< charT, traits > &  stream,
run_parts const &  rhs 
)
friend

Output the environment to an ostream.

Parameters
streamthe stream to output to.
rhsthe environment to output.
Returns
the stream.

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