MySQL 8.0.39
Source Code Documentation
|
#include <process_launcher.h>
Public Types | |
enum class | ShutdownEvent { TERM , KILL , ABRT } |
using | exit_status_type = ExitStatus |
using | process_handle_type = SpawnedProcess::handle_type |
using | process_id_type = SpawnedProcess::id_type |
Public Types inherited from mysql_harness::SpawnedProcess | |
using | handle_type = pid_t |
using | id_type = pid_t |
Public Member Functions | |
ProcessLauncher (std::string pexecutable_path, std::vector< std::string > pargs, std::vector< std::pair< std::string, std::string > > penv_vars, bool predirect_stderr=true) | |
Creates a new process and launch it. More... | |
ProcessLauncher (const ProcessLauncher &)=delete | |
ProcessLauncher | operator= (const ProcessLauncher &)=delete |
ProcessLauncher (ProcessLauncher &&rhs) | |
~ProcessLauncher () override | |
void | start () |
Launches the child process, and makes pipes available for read/write. More... | |
int | read (char *buf, size_t count, std::chrono::milliseconds timeout) |
Read up to a 'count' bytes from the stdout of the child process. More... | |
int | write (const char *buf, size_t count) |
Writes several butes into stdin of child process. More... | |
exit_status_type | kill () |
Kills the child process and returns process' exit code. More... | |
process_id_type | get_pid () const |
Returns the child process id. More... | |
process_handle_type | get_process_handle () const |
Returns the child process handle. More... | |
stdx::expected< exit_status_type, std::error_code > | exit_code () |
get exit-code. More... | |
int | wait (std::chrono::milliseconds timeout=std::chrono::milliseconds(1000)) |
Wait for the child process to exists and returns its exit code. More... | |
exit_status_type | native_wait (std::chrono::milliseconds timeout=std::chrono::milliseconds(1000)) |
void | end_of_write () |
Closes pipe to process' STDIN in order to notify the process that all data was sent. More... | |
std::error_code | send_shutdown_event (ShutdownEvent event=ShutdownEvent::TERM) const noexcept |
Sends a shutdown event to child process (SIGTERM on Unix, Ctrl+C on Win) More... | |
Public Member Functions inherited from mysql_harness::SpawnedProcess | |
SpawnedProcess (std::string pexecutable_path, std::vector< std::string > pargs, std::vector< std::pair< std::string, std::string > > penv_vars, bool predirect_stderr=true) | |
SpawnedProcess (const SpawnedProcess &)=default | |
virtual | ~SpawnedProcess ()=default |
std::string | get_cmd_line () const |
std::string | executable () const |
Private Member Functions | |
exit_status_type | close () |
Closes child process and returns process' exit code. More... | |
Private Attributes | |
std::mutex | fd_in_mtx_ |
std::mutex | fd_out_mtx_ |
bool | is_alive |
Additional Inherited Members | |
Protected Attributes inherited from mysql_harness::SpawnedProcess | |
const std::string | executable_path |
const std::vector< std::string > | args |
const std::vector< std::pair< std::string, std::string > > | env_vars |
pid_t | childpid |
int | fd_in [2] |
int | fd_out [2] |
bool | redirect_stderr |
|
strong |
|
inline |
Creates a new process and launch it.
If redirect_stderr is true, the child's stderr is redirected to the same stream than child's stdout.
|
delete |
|
inline |
|
override |
|
private |
Closes child process and returns process' exit code.
std::system_error | if sending signal to child process fails |
std::runtime_error | if waiting for process to change state fails |
void mysql_harness::ProcessLauncher::end_of_write | ( | ) |
Closes pipe to process' STDIN in order to notify the process that all data was sent.
stdx::expected< ProcessLauncher::exit_status_type, std::error_code > mysql_harness::ProcessLauncher::exit_code | ( | ) |
get exit-code.
ProcessLauncher::process_handle_type mysql_harness::ProcessLauncher::get_pid | ( | ) | const |
Returns the child process id.
ProcessLauncher::process_handle_type mysql_harness::ProcessLauncher::get_process_handle | ( | ) | const |
Returns the child process handle.
ProcessLauncher::exit_status_type mysql_harness::ProcessLauncher::kill | ( | ) |
Kills the child process and returns process' exit code.
ProcessLauncher::exit_status_type mysql_harness::ProcessLauncher::native_wait | ( | std::chrono::milliseconds | timeout = std::chrono::milliseconds(1000) | ) |
|
delete |
int mysql_harness::ProcessLauncher::read | ( | char * | buf, |
size_t | count, | ||
std::chrono::milliseconds | timeout | ||
) |
Read up to a 'count' bytes from the stdout of the child process.
This method blocks until the amount of bytes is read or specified timeout expires.
buf | already allocated buffer where the read data will be stored. |
count | the maximum amount of bytes to read. |
timeout | timeout (in milliseconds) for the read to complete |
|
noexcept |
Sends a shutdown event to child process (SIGTERM on Unix, Ctrl+C on Win)
event | type of shutdown event |
void mysql_harness::ProcessLauncher::start | ( | ) |
Launches the child process, and makes pipes available for read/write.
int mysql_harness::ProcessLauncher::wait | ( | std::chrono::milliseconds | timeout = std::chrono::milliseconds(1000) | ) |
Wait for the child process to exists and returns its exit code.
If the child process is already dead, wait() just returns.
std::runtime_error | if process exited with a signal |
int mysql_harness::ProcessLauncher::write | ( | const char * | buf, |
size_t | count | ||
) |
Writes several butes into stdin of child process.
Returns an shcore::Exception in case of error when writing.
|
private |
|
private |
|
private |