minishell
Minishell Project for École 42
Loading...
Searching...
No Matches
child_handler_multi.c File Reference

Functions for handling child processes in a multi-command. More...

#include "minishell.h"
Include dependency graph for child_handler_multi.c:

Functions

int handle_redirections_pipeline (int *fildes, t_executor *current, t_info *info)
 Handles file redirections and file descriptor setup.
 
void execute_builtin_child (t_executor *current, t_info *info)
 Executes a built-in command in a child process and exits.
 
char * execute_other_helper (t_executor *current)
 Helper function to find the executable path.
 
int execute_other (t_executor *current, t_info *info)
 Executes a non-built-in command in a child process using execve.
 
int child_handler_multi (int *fildes, t_executor *current, t_info *info)
 Handles the execution of a child process in a multi-command.
 

Detailed Description

Functions for handling child processes in a multi-command.

Function Documentation

◆ child_handler_multi()

int child_handler_multi ( int *  fildes,
t_executor current,
t_info info 
)

Handles the execution of a child process in a multi-command.

This function handles the execution of a child process, including setting up file descriptors, executing built-in or non-built-in commands, and managing the child process's exit status.

Parameters
fildesArray of pipe file descriptors.
currentThe current node of the executor list representing a command.
infoPointer to the t_info structure.
Returns
FAIL_SYSCALL_CHILD on failure (should not return if successful).

◆ execute_builtin_child()

void execute_builtin_child ( t_executor current,
t_info info 
)

Executes a built-in command in a child process and exits.

This function executes a built-in command in a child process, sets the exit code accordingly, frees the heap and then exits the child process.

Parameters
currentThe current node of the executor list representing a command.
infoPointer to the t_info structure.

◆ execute_other()

int execute_other ( t_executor current,
t_info info 
)

Executes a non-built-in command in a child process using execve.

This function executes a non-built-in command in a child process using the execve() system call and sets the exit code accordingly. If the path is not absolute then it uses execute_other_helper() to get one. Before the execve() call the function transforms the env list into a 2D array in order to pass it to execve().

Parameters
currentThe current node of the executor list representing a command.
infoPointer to the t_info structure.
Returns
FAIL_SYSCALL on failure (should not return if successful).

◆ execute_other_helper()

char * execute_other_helper ( t_executor current)

Helper function to find the executable path.

This function searches for the executable in the directories listed in the PATH environment variable and returns the full path to the executable.

Parameters
currentThe current node of the executor list representing a command.
Returns
The full path to the executable or NULL on failure.

◆ handle_redirections_pipeline()

int handle_redirections_pipeline ( int *  fildes,
t_executor current,
t_info info 
)

Handles file redirections and file descriptor setup.

Sets up file descriptors for a child process in a pipeline, including standard input and output redirection. Manages file descriptors for communication if more commands are in the pipeline.

Parameters
fildesArray of pipe file descriptors.
currentThe current node of the executor list representing a command.
infoPointer to the t_info structure.
Returns
OKAY on success, FAIL_SYSCALL on failure.