FlatImage
A configurable Linux containerization system
Loading...
Searching...
No Matches
portal_dispatcher.cpp File Reference

Dispatches child process requests to the portal daemon. More...

#include <chrono>
#include <csignal>
#include <cstdlib>
#include <expected>
#include <fcntl.h>
#include <filesystem>
#include <sys/prctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include "../macro.hpp"
#include "../std/expected.hpp"
#include "../std/filesystem.hpp"
#include "../lib/env.hpp"
#include "../lib/log.hpp"
#include "../lib/linux.hpp"
#include "../lib/linux/fifo.hpp"
#include "../lib/linux/fd.hpp"
#include "../db/portal/message.hpp"
#include "../db/portal/dispatcher.hpp"
#include "config.hpp"
Include dependency graph for portal_dispatcher.cpp:

Go to the source code of this file.

Functions

void signal_handler (int sig)
 Forwards received signal to requested child process.
 
void register_signals ()
 Registers signal handlers for dispatcher cleanup.
 
Value< void > fifo_create (ns_message::Message const &msg)
 Creates FIFOs for child process I/O.
 
Value< void > send_message (ns_message::Message const &message, fs::path const &path_fifo_daemon)
 Sends a message to the portal daemon.
 
Value< int > process_wait (ns_message::Message const &message)
 Waits for the requested process to finish.
 
Value< int > process_request (fs::path const &path_fifo_daemon, fs::path const &path_dir_fifo, std::vector< std::string > const &cmd)
 Sends a request to the daemon to create a new process.
 
int main (int argc, char **argv)
 Entry point for the portal dispatcher.
 

Variables

char ** environ
 
std::optional< pid_t > opt_child = std::nullopt
 

Detailed Description

Dispatches child process requests to the portal daemon.

Author
Ruan Formigoni

Definition in file portal_dispatcher.cpp.

Function Documentation

◆ fifo_create()

Value< void > fifo_create ( ns_message::Message const & msg)
nodiscard

Creates FIFOs for child process I/O.

Parameters
msgMessage containing FIFO paths for stdin, stdout, and stderr
Returns
Value<void> Success or error

Definition at line 83 of file portal_dispatcher.cpp.

Here is the caller graph for this function:

◆ main()

int main ( int argc,
char ** argv )

Entry point for the portal dispatcher.

Parameters
argcArgument count
argvArgument vector
Returns
int Exit code (0 for success, non-zero for failure)

Definition at line 202 of file portal_dispatcher.cpp.

Here is the call graph for this function:

◆ process_request()

Value< int > process_request ( fs::path const & path_fifo_daemon,
fs::path const & path_dir_fifo,
std::vector< std::string > const & cmd )
nodiscard

Sends a request to the daemon to create a new process.

Parameters
cmdCommand to request, with it's respective arguments
daemon_target"host" sends a command to the 'host' daemon and "guest" sends a command to the 'guest' daemon
path_dir_instancePath to the instance directory to use
Returns
Value<int> The process return code or the respective error

Definition at line 173 of file portal_dispatcher.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_wait()

Value< int > process_wait ( ns_message::Message const & message)
nodiscard

Waits for the requested process to finish.

Forwards the child's stdin/stdout/stderr to itself

Parameters
messageThe message containing the FIFO paths
Returns
Value<int> The process exit code or the respective error

Definition at line 125 of file portal_dispatcher.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_signals()

void register_signals ( )

Registers signal handlers for dispatcher cleanup.

Registers handlers for various signals (SIGINT, SIGTERM, etc.) to ensure proper cleanup when the dispatcher receives termination signals.

Definition at line 59 of file portal_dispatcher.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_message()

Value< void > send_message ( ns_message::Message const & message,
fs::path const & path_fifo_daemon )
nodiscard

Sends a message to the portal daemon.

Parameters
path_fifo_daemonPath to the fifo which the daemon receives commands from
messageThe message to send
Returns
Value<void> Nothing on success or the respective error

Definition at line 100 of file portal_dispatcher.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ signal_handler()

void signal_handler ( int sig)

Forwards received signal to requested child process.

Parameters
sigThe signal to forward

Definition at line 45 of file portal_dispatcher.cpp.

Here is the caller graph for this function:

Variable Documentation

◆ opt_child

std::optional<pid_t> opt_child = std::nullopt

Definition at line 38 of file portal_dispatcher.cpp.