sbuild
1.7.1
|
Run all scripts or programs within a directory. More...
#include <run-parts.h>
Public Types | |
enum | error_code { CHILD_FORK, CHILD_WAIT, EXEC, PIPE, DUP, POLL, READ } |
Error codes. More... | |
typedef custom_error< error_code > | error |
Exception type. | |
Public Member Functions | |
run_parts (const std::string &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 (const string_list &command, const environment &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 (const std::string &file, const string_list &command, const environment &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, const run_parts &rhs) |
Output the environment to an ostream. More... | |
Run all scripts or programs within a directory.
sbuild::run_parts::run_parts | ( | const std::string & | directory, |
bool | lsb_mode = true , |
||
bool | abort_on_error = true , |
||
mode_t | umask = 022 |
||
) |
The constructor.
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. |
References sbuild::is_valid_filename(), and programs.
bool sbuild::run_parts::get_reverse | ( | ) | const |
Get the script execution order.
References reverse.
bool sbuild::run_parts::get_verbose | ( | ) | const |
int sbuild::run_parts::run | ( | const string_list & | command, |
const environment & | env | ||
) |
Run all scripts in the specified directory.
If abort_on_error is true, execution will stop at the first script to fail.
command | the command to run. |
env | the environment to use. |
References abort_on_error, programs, reverse, and run_child().
Referenced by sbuild::session::setup_chroot().
|
private |
Run the command specified by file (an absolute pathname), using command and env as the argv and environment, respectively.
file | the program to execute. |
command | the arguments to pass to the executable. |
env | the environment. |
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().
void sbuild::run_parts::set_reverse | ( | bool | reverse) |
Set the script execution order.
reverse | true to execute in reverse, otherwise false. |
References reverse.
Referenced by sbuild::session::setup_chroot().
void sbuild::run_parts::set_verbose | ( | bool | verbose) |
Set the verbosity level.
verbose | true to be verbose, otherwise false. |
References verbose.
Referenced by sbuild::session::setup_chroot().
|
private |
Wait for a child process to complete, and check its exit status.
An error will be thrown on failure.
pid | the pid to wait for. |
child_status | the place to store the child exit status. |
References CHILD_WAIT.
Referenced by run_child().
|
friend |
Output the environment to an ostream.
stream | the stream to output to. |
rhs | the environment to output. |