- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- Class List
- Class Hierarchy
- Class 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:

[legend]
List of all members.

## Public Types
typedef custom_error< error_code > | error
| Exception type.
| CHILD_FORK
| Failed to fork child.
| CHILD_WAIT
| Wait for child failed.
| EXEC
| Failed to execute.
enum | error_code { CHILD_FORK, CHILD_WAIT, EXEC }
| Error codes. More...
## Public Member Functions
| run_parts (std::string const &directory, bool lsb_mode=true, bool abort_on_error=true, mode_t umask=022)
| The constructor.
| ~run_parts ()
| The destructor.
bool | get_verbose () const
| Get the verbosity level.
void | set_verbose (bool verbose)
| Set the verbosity level.
bool | get_reverse () const
| Get the script execution order.
void | set_reverse (bool reverse)
| Set the script execution order.
int | run (string_list const &command, environment const &env)
| Run all scripts in the specified directory.
## 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.
void | wait_for_child (pid_t pid, int &child_status)
| Wait for a child process to complete, and check its exit status.
bool | check_filename (std::string const &name)
| Check a filename matches the allowed pattern(s).
## 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.

## Detailed Description

Run all scripts or programs within a directory.

## Member Typedef Documentation

typedef custom_error<error_code> sbuild::run_parts::error

Exception type.

typedef std::set<std::string> sbuild::run_parts::program_set`[private]`

A sorted set of filenames to use.

## Member Enumeration Documentation

enum sbuild::run_parts::error_code

Error codes.

Enumerator:

  CHILD_FORK | Failed to fork child.
  CHILD_WAIT | Wait for child failed.
  EXEC | Failed to execute.

## 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:

  | directory | the directory to run scripts from.
  | lsb_mode | use 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_error | stop executing scripts if one returns an error.
  | umask | the umask to set when running scripts.

run_parts::~run_parts | ( |  | ) |

The destructor.

## Member Function Documentation

bool run_parts::check_filename | ( | std::string const & | name | ) | `[private]`

Check a filename matches the allowed pattern(s).

Parameters:

  | name | the filename to check.

Returns:
  true if it matches, false if not.

bool run_parts::get_reverse | ( |  | ) | const

Get the script execution order.

Returns:
  true if executing in reverse, otherwise false.

bool run_parts::get_verbose | ( |  | ) | const

Get the verbosity level.

Returns:
  true if verbose, otherwise false.

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:

  | command | the command to run.
  | env | the 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.

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:

  | file | the program to execute.
  | command | the arguments to pass to the executable.
  | env | the environment.

Returns:
  the return value of the execve system call on failure.

void run_parts::set_reverse | ( | bool | reverse | ) |

Set the script execution order.

Parameters:

  | reverse | true to execute in reverse, otherwise false.

void run_parts::set_verbose | ( | bool | verbose | ) |

Set the verbosity level.

Parameters:

  | verbose | true to be verbose, otherwise false.

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:

  | pid | the pid to wait for.
  | child_status | the place to store the child exit status.

Todo:
  Use waitpid instead of wait.

## 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:

  | stream | the stream to output to.
  | rhs | the environment to output.

Returns:
  the stream.

## Member Data Documentation

bool sbuild::run_parts::abort_on_error`[private]`

Whether to abort on script execution error.

std::string sbuild::run_parts::directory`[private]`

The directory to run scripts from.

bool sbuild::run_parts::lsb_mode`[private]`

The LSB mode for allowed filenames.

program_set sbuild::run_parts::programs`[private]`

The list of scripts to run.

bool sbuild::run_parts::reverse`[private]`

Execute scripts in reverse order.

mode_t sbuild::run_parts::umask`[private]`

The umask to run scripts with.

bool sbuild::run_parts::verbose`[private]`

Verbose logging.

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

- sbuild/sbuild-run-parts.h
- sbuild/sbuild-run-parts.cc