DUNE-DAQ
DUNE Trigger and Data Acquisition software
|
Wrapper for executable file manipulation. More...
#include <Executable.hpp>
Public Types | |
typedef std::vector< std::string > | param_collection |
typedef std::map< std::string, std::string > | env_collection |
![]() | |
typedef std::vector< OksSystem::File > | file_list_t |
Public Member Functions | |
Executable (const OksSystem::File &file) | |
Executable (const char *filename) | |
Executable (const std::string &filename) | |
~Executable () | |
void | exec () const |
run the executable | |
void | exec (const param_collection ¶ms) const |
run the executable | |
std::string | pipe_in (const param_collection ¶ms) const |
run the executable and pipe results back | |
std::string | pipe_in (const param_collection ¶ms, const env_collection &envs) const |
Process | pipe_out (const param_collection ¶ms, const File &input_file, const File &output_file, const File &error_file, mode_t perm) const |
Process | pipe_out (const param_collection ¶ms, const env_collection &envs, const File &input_file, const File &output_file, const File &error_file, mode_t perm) const |
void | exec (const param_collection ¶ms, const env_collection &envs) const |
run the executable | |
Process | start (const param_collection ¶ms) const |
start the executable in another process | |
Process | start_and_forget (const param_collection ¶ms) const |
start the executable in another process; do not wait for termination of child | |
Process | start (const param_collection ¶ms, const env_collection &envs) const |
start the executable in another process | |
std::string | to_string (const param_collection ¶ms) const |
converts executable name and a parameter sequence into a string | |
![]() | |
File (const std::string &name) | |
File (const char *name) | |
File (const File &other) | |
virtual | ~File () |
operator std::string () const throw () | |
operator const char * () const throw () | |
operator bool () const throw () | |
bool | equals (const File &other) const throw () |
compare two files */ | |
operator size_t () const | |
const std::string & | full_name () const throw () |
full name for file */ | |
const char * | c_full_name () const throw () |
std::string | short_name () const throw () |
short name for file */ | |
std::string | parent_name () const throw () |
path of directory containing file */ | |
std::string | extension () const throw () |
extension for file */ | |
int | depth () const throw () |
depth of the file */ | |
OksSystem::File | parent () const |
parent of the current file */ | |
OksSystem::File | child (const std::string &name) const |
named child of the current directory */ | |
OksSystem::File | temporary (const std::string &prefix) const |
bool | exists () const throw () |
does the file exist */ | |
mode_t | permissions () const |
permissions for the file */ | |
std::string | pretty_permissions () const |
pretty permissions for the file */ | |
size_t | size () const |
size of file */ | |
uid_t | owner_id () const |
owner id of file */ | |
User | owner () const |
owner of the file */ | |
gid_t | group () const |
group of file */ | |
bool | is_regular () const |
is the file a directory */ | |
bool | is_directory () const |
is the file a regular file */ | |
bool | is_fifo () const |
is the file a named pipe */ | |
std::string | file_type () const |
type of the file */ | |
file_list_t | directory () const |
list of file in directory */ | |
void | unlink () const |
deletes (unlinks) file */ | |
void | rmdir () const |
deletes directory */ | |
void | remove () const |
recursively delete files and directories */ | |
void | rename (const File &other) const |
rename or moves the file */ | |
void | permissions (mode_t permissions) const |
sets the type of the file */ | |
void | make_dir (mode_t permissions) const |
creates a directory */ | |
void | make_path (mode_t permissions) const |
creates a full path */ | |
void | make_fifo (mode_t permissions) const |
creates a FIFO (named pipe) */ | |
void | ensure_path (mode_t permissions) const |
creates the parent path */ | |
std::istream * | input () const |
returns an input stream from the file*/ | |
std::ostream * | output (bool append=false) const |
returns an output stream to the file*/ | |
Static Public Member Functions | |
static std::string | okssystem (const std::string &command) |
execute a command in a shell | |
![]() | |
static std::string | protocol (const std::string &url) throw () |
extracts the protocol part of an url */ | |
static std::string | extension (const std::string &url) throw () |
extracts the extension of a path or an url */ | |
static std::string | uri (const std::string &url) throw () |
extracts the local path of an url */ | |
static std::string | short_name (const std::string &url) throw () |
extracts the short file name of an url */ | |
static int | depth (const std::string &path) throw () |
calculates depth of a path */ | |
static std::string | first_line (const std::string &text) |
extracts the first line of a text */ | |
static File | from_url (const std::string &url) |
build a file out of an URL */ | |
static std::string | working_directory () |
current directory of process */ | |
static void | working_directory (const File &dir) |
set working directory of process */ | |
static std::string | expand_home (const std::string path) |
resolve home directory */ | |
static std::string | pretty_permissions (mode_t permissions) |
pretty prints permissions */ | |
static std::string | to_string (mode_t permissions) throw () |
converts permission to string */ | |
static std::string | pretty_open_flag (int flags) |
pretty prints open flags */ | |
static std::string | pretty_size (size_t size, bool cut_small) |
pretty prints a file size */ | |
Protected Member Functions | |
void | exec (char **argv) const |
does the actual exec | |
void | exec (char **const argv, char **const env) const |
does the actual exec setting the right environment for the child process | |
![]() | |
void | set_name (const std::string &name) |
sets the name of the file */ | |
mode_t | get_mode () const |
get mode associated with file (permission + type) */ | |
Static Protected Member Functions | |
static void | copy_fd (int fd, std::ostream &target) |
copies the content of a file descriptor into a STL stream | |
![]() | |
static int | unit (int u) |
calculates the value of a computer unit of order n (i.e KB,GB, etc */ | |
Static Protected Attributes | |
static const char *const | SHELL_COMMAND = "/bin/sh" |
command to execute in a shell | |
static const char *const | SHELL_COMMAND_PARAM = "-c" |
parameter to execute in a shell | |
![]() | |
static const char *const | HUMAN_SIZE_STR [] = { "B", "KB", "MB", "GB" } |
strings for pretty printing file sizes */ | |
static const char *const | HUMAN_OPEN_STR [] = { "READ", "WRITE", "NOBLOCK", "APPEND", "CREATE", "TRUNCATE","EXCLUSIVE" } |
strings for pretty printing open flags */ | |
static const int | KILOBYTE = 1024 |
number of bytes in a kilobyte */ | |
static const char *const | FILE_COMMAND_PATH = "/usr/bin/file" |
Additional Inherited Members | |
![]() | |
static const char *const | FILE_FLAG_STR = "-rwxS" |
column headers for display of permissions */ | |
static const char *const | FILE_PROTOCOL = "file" |
string for the file protocol */ | |
![]() | |
std::string | m_full_name |
full name (path) of the file */ | |
Wrapper for executable file manipulation.
This class represents an executable file, that is a program. The class offers facilities to launch the program with given parameters environnement variables
Definition at line 29 of file Executable.hpp.
std::map<std::string, std::string> OksSystem::Executable::env_collection |
Definition at line 33 of file Executable.hpp.
std::vector<std::string> OksSystem::Executable::param_collection |
Definition at line 32 of file Executable.hpp.
OksSystem::Executable::Executable | ( | const OksSystem::File & | file | ) |
Definition at line 54 of file Executable.cpp.
OksSystem::Executable::Executable | ( | const char * | filename | ) |
Definition at line 55 of file Executable.cpp.
OksSystem::Executable::Executable | ( | const std::string & | filename | ) |
Definition at line 56 of file Executable.cpp.
OksSystem::Executable::~Executable | ( | ) |
Definition at line 57 of file Executable.cpp.
|
staticprotected |
copies the content of a file descriptor into a STL stream
Copies the content of a file descriptor into a STL stream
fd | the source file descriptor |
target | the target stream |
Definition at line 311 of file Executable.cpp.
void OksSystem::Executable::exec | ( | ) | const |
run the executable
|
protected |
does the actual exec
Core execution method. This method assumes the datastructures have been setup correctly for execv
. It basically adds some error handling to execv
argv | array of arguments, with name of the executable in first position |
Definition at line 67 of file Executable.cpp.
|
protected |
does the actual exec
setting the right environment for the child process
Core execution method. This method assumes the datastructures have been setup correctly for execve
. It basically adds some error handling to execve
. Look at the execve
man pages for details.
argv | array of arguments, with name of the executable in first position |
env | array containing the environment the process will be started with |
Definition at line 81 of file Executable.cpp.
void OksSystem::Executable::exec | ( | const param_collection & | params | ) | const |
run the executable
Simple execution method. This methods converts the vector of strings into the correct data structures for execv
. The argv
structure is allocated dynamically and new string copied into it.
Definition at line 94 of file Executable.cpp.
void OksSystem::Executable::exec | ( | const param_collection & | params, |
const env_collection & | envs ) const |
run the executable
This execution method calls the 'execve' function executing the
params | the parameters to use when launching the executable |
envs | table of the environnement variables set for the executable |
Definition at line 130 of file Executable.cpp.
|
static |
execute a command in a shell
This method is a safe replacement for the okssystem function. It basically offers the same functionality with better error handling. The command is executed in a shell via /bin/sh
-c
. If the command is successfull (return value 0), this method returns the resulting string.
If the command fails, this method throws an exception of type okssystem::ExecutionIssue
. This exception contains the return code and the content of stderr.
command | the command to execute |
Definition at line 46 of file Executable.cpp.
std::string OksSystem::Executable::pipe_in | ( | const param_collection & | params | ) | const |
run the executable and pipe results back
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 325 of file Executable.cpp.
std::string OksSystem::Executable::pipe_in | ( | const param_collection & | params, |
const env_collection & | envs ) const |
This method executes the process and pipes stdout and stderr back and waits for execution termination. If the return value is zero then the content of stdout is copied into a string and returned. In case of a non-zero value, an exception is thrown. This exception contains the return code and the content of stderr.
params | the parameters to the executable |
envs | the environnement variables to set |
OksSystem::ExecutionIssue | if command execution did not return 0. |
OksSystem::ExecFail | if the exec okssystem call failed. |
OksSystem::PipeIssue | if the pipe okssystem call failed. |
Definition at line 418 of file Executable.cpp.
OksSystem::Process OksSystem::Executable::pipe_out | ( | const param_collection & | params, |
const env_collection & | envs, | ||
const File & | input_file, | ||
const File & | output_file, | ||
const File & | error_file, | ||
mode_t | perm ) const |
Runs the executable and redirects the two output streams
params | the parameters for the executable |
envs | the environnements for the executable |
input_file | the input file for stdin |
output_file | the output file for stdout |
error_file | the output file for stderr |
perm | permissions for both output streams |
Definition at line 493 of file Executable.cpp.
OksSystem::Process OksSystem::Executable::pipe_out | ( | const param_collection & | params, |
const File & | input_file, | ||
const File & | output_file, | ||
const File & | error_file, | ||
mode_t | perm ) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 425 of file Executable.cpp.
OksSystem::Process OksSystem::Executable::start | ( | const param_collection & | params | ) | const |
start the executable in another process
This method starts the executable in another process using fork
params | the parameters to use when launching the executable |
Definition at line 204 of file Executable.cpp.
OksSystem::Process OksSystem::Executable::start | ( | const param_collection & | params, |
const env_collection & | envs ) const |
start the executable in another process
This method starts the executable in another process using fork
params | the parameters to use when launching the executable |
envs | table of the environnement variables set for the executable |
Definition at line 558 of file Executable.cpp.
OksSystem::Process OksSystem::Executable::start_and_forget | ( | const param_collection & | params | ) | const |
start the executable in another process; do not wait for termination of child
This method starts the executable in another process using fork
. The parent will not wait on the child termination.
params | the parameters to use when launching the executable |
Definition at line 256 of file Executable.cpp.
std::string OksSystem::Executable::to_string | ( | const param_collection & | params | ) | const |
converts executable name and a parameter sequence into a string
Converts the executable name and a list of parameters into a string, suitable for display.
params | the list of parameters |
Definition at line 609 of file Executable.cpp.
|
staticprotected |
command to execute in a shell
Definition at line 37 of file Executable.hpp.
|
staticprotected |
parameter to execute in a shell
Definition at line 38 of file Executable.hpp.