MySQL 8.4.0
Source Code Documentation
mysql_harness::ProcessLauncher Class Reference

#include <process_launcher.h>

Inheritance diagram for mysql_harness::ProcessLauncher:
[legend]

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
 

Member Typedef Documentation

◆ exit_status_type

◆ process_handle_type

◆ process_id_type

Member Enumeration Documentation

◆ ShutdownEvent

Enumerator
TERM 
KILL 
ABRT 

Constructor & Destructor Documentation

◆ ProcessLauncher() [1/3]

mysql_harness::ProcessLauncher::ProcessLauncher ( std::string  pexecutable_path,
std::vector< std::string >  pargs,
std::vector< std::pair< std::string, std::string > >  penv_vars,
bool  predirect_stderr = true 
)
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.

◆ ProcessLauncher() [2/3]

mysql_harness::ProcessLauncher::ProcessLauncher ( const ProcessLauncher )
delete

◆ ProcessLauncher() [3/3]

mysql_harness::ProcessLauncher::ProcessLauncher ( ProcessLauncher &&  rhs)
inline

◆ ~ProcessLauncher()

mysql_harness::ProcessLauncher::~ProcessLauncher ( )
override

Member Function Documentation

◆ close()

ProcessLauncher::exit_status_type mysql_harness::ProcessLauncher::close ( )
private

Closes child process and returns process' exit code.

Exceptions
std::system_errorif sending signal to child process fails
std::runtime_errorif waiting for process to change state fails
Returns
process exit code.

◆ end_of_write()

void mysql_harness::ProcessLauncher::end_of_write ( )

Closes pipe to process' STDIN in order to notify the process that all data was sent.

◆ exit_code()

stdx::expected< ProcessLauncher::exit_status_type, std::error_code > mysql_harness::ProcessLauncher::exit_code ( )

get exit-code.

◆ get_pid()

ProcessLauncher::process_handle_type mysql_harness::ProcessLauncher::get_pid ( ) const

Returns the child process id.

◆ get_process_handle()

ProcessLauncher::process_handle_type mysql_harness::ProcessLauncher::get_process_handle ( ) const

Returns the child process handle.

◆ kill()

ProcessLauncher::exit_status_type mysql_harness::ProcessLauncher::kill ( )

Kills the child process and returns process' exit code.

◆ native_wait()

ProcessLauncher::exit_status_type mysql_harness::ProcessLauncher::native_wait ( std::chrono::milliseconds  timeout = std::chrono::milliseconds(1000))

◆ operator=()

ProcessLauncher mysql_harness::ProcessLauncher::operator= ( const ProcessLauncher )
delete

◆ read()

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.

Parameters
bufalready allocated buffer where the read data will be stored.
countthe maximum amount of bytes to read.
timeouttimeout (in milliseconds) for the read to complete
Returns
the real number of bytes read. Returns an shcore::Exception in case of error when reading.

◆ send_shutdown_event()

std::error_code mysql_harness::ProcessLauncher::send_shutdown_event ( ShutdownEvent  event = ShutdownEvent::TERM) const
noexcept

Sends a shutdown event to child process (SIGTERM on Unix, Ctrl+C on Win)

Parameters
eventtype of shutdown event
Returns
std::error_code indicating success/failure

◆ start()

void mysql_harness::ProcessLauncher::start ( )

Launches the child process, and makes pipes available for read/write.

◆ wait()

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.

Returns
the exit code of the process.
Exceptions
std::runtime_errorif process exited with a signal

◆ write()

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.

Member Data Documentation

◆ fd_in_mtx_

std::mutex mysql_harness::ProcessLauncher::fd_in_mtx_
private

◆ fd_out_mtx_

std::mutex mysql_harness::ProcessLauncher::fd_out_mtx_
private

◆ is_alive

bool mysql_harness::ProcessLauncher::is_alive
private

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