|
FlatImage
A configurable Linux containerization system
|
Inter-process pipe management. More...
Functions | |
| void | write_pipe (pid_t child_pid, int pipe_fd, std::istream &stream) |
| Write from an input stream to a pipe file descriptor. | |
| void | read_pipe (pid_t child_pid, int pipe_fd, std::ostream &stream, std::filesystem::path const &path_file_log) |
| Read from a pipe file descriptor and write to an output stream. | |
| template<typename Stream> | |
| bool | is_standard_stream (Stream &stream) |
| Check if a stream is a standard stream (std::cin, std::cout, or std::cerr) | |
| template<typename Stream> | |
| void | pipes_child (bool is_istream, int pipe[2], Stream &stream, int fileno) |
| Setup pipe for child process (unified for stdin/stdout/stderr) | |
| template<typename Stream> | |
| std::optional< std::jthread > | pipes_parent (pid_t child_pid, bool is_istream, int pipe[2], Stream &stream, std::filesystem::path const &path_file_log) |
| Setup pipe for parent process (unified for stdin/stdout/stderr) | |
| std::vector< std::jthread > | setup (pid_t pid, int pipestdin[2], int pipestdout[2], int pipestderr[2], std::istream &stdin, std::ostream &stdout, std::ostream &stderr, std::filesystem::path const &path_file_log) |
| Handle pipe setup for both parent and child processes. | |
Inter-process pipe management.
Manages Unix pipe creation, configuration, and cleanup for inter-process communication. Handles file descriptor management with RAII semantics, read/write end access, and automatic closing on destruction for safe stdio redirection in child processes.
Check if a stream is a standard stream (std::cin, std::cout, or std::cerr)
| Stream | The stream type (std::istream or std::ostream) |
| stream | The stream reference to check |
Definition at line 92 of file pipe.hpp.
| void ns_subprocess::ns_pipe::pipes_child | ( | bool | is_istream, |
| int | pipe[2], | ||
| Stream & | stream, | ||
| int | fileno ) |
Setup pipe for child process (unified for stdin/stdout/stderr)
| Stream | The stream type (std::istream or std::ostream) |
| is_istream | True for input streams (stdin), false for output streams (stdout/stderr) |
| pipe | Pipe array [read_end, write_end] |
| stream | The stream reference to check |
| fileno | The file descriptor to redirect to (STDIN_FILENO, STDOUT_FILENO, or STDERR_FILENO) |
Definition at line 115 of file pipe.hpp.
| std::optional< std::jthread > ns_subprocess::ns_pipe::pipes_parent | ( | pid_t | child_pid, |
| bool | is_istream, | ||
| int | pipe[2], | ||
| Stream & | stream, | ||
| std::filesystem::path const & | path_file_log ) |
Setup pipe for parent process (unified for stdin/stdout/stderr)
| Stream | The stream type (std::istream or std::ostream) |
| child_pid | PID of child process (needed for stdin writer) |
| is_istream | True for input streams (stdin), false for output streams (stdout/stderr) |
| pipe | Pipe array [read_end, write_end] |
| stream | The stream reference to use |
| path_file_log | Optional log file path (unused for stdin) |
Definition at line 149 of file pipe.hpp.
|
inline |
Read from a pipe file descriptor and write to an output stream.
Reads data from the pipe and writes it to the output stream. Handles line splitting and filtering of empty/whitespace-only lines. Replaces carriage returns with newlines to handle Windows-style line endings and progress updates.
| child_pid | PID of the child process to monitor |
| pipe_fd | File descriptor of the pipe read end |
| stream | Output stream to write to |
| path_file_log | Log file path for logging output |
Definition at line 72 of file pipe.hpp.
|
inline |
Handle pipe setup for both parent and child processes.
This function manages the pipe setup after fork():
Standard streams (std::cin, std::cout, std::cerr) are not redirected, allowing terminal access.
| pid | Process ID from fork() (0 for child, >0 for parent) |
| pipestdin | Stdin pipe array [read_end, write_end] |
| pipestdout | Stdout pipe array [read_end, write_end] |
| pipestderr | Stderr pipe array [read_end, write_end] |
| stdin | Input stream to read from (for child's stdin) |
| stdout | Output stream to write to (for child's stdout) |
| stderr | Error stream to write to (for child's stderr) |
| path_file_log | Log file path for pipe reader threads |
Definition at line 204 of file pipe.hpp.
|
inline |
Write from an input stream to a pipe file descriptor.
Reads lines from the input stream and writes them to the pipe. Continues until the child process exits or stream errors occur.
| child_pid | PID of the child process to monitor |
| pipe_fd | File descriptor of the pipe write end |
| stream | Input stream to read from |
Definition at line 53 of file pipe.hpp.