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

Functions related to handling multiple commands inside a pipeline. More...

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

Functions

t_infoinit_info (t_shell *shell)
 Initializes the t_info structure.
 
void wait_pipeline (t_info *info, int number)
 Wait for child processes to finish execution + update the exit code.
 
void ft_error (t_executor *current, t_info *info)
 Handle errors during command execution and set the exit code accordingly.
 
void handle_multi (t_shell *shell, t_executor *current)
 Handles the execution of multiple commands.
 

Detailed Description

Functions related to handling multiple commands inside a pipeline.

Function Documentation

◆ ft_error()

void ft_error ( t_executor current,
t_info info 
)

Handle errors during command execution and set the exit code accordingly.

This function checks for specific error conditions during command execution (e.g., command not found or permission denied) and sets the exit code accordingly before exiting. Afterwards it frees everything in heap.

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

◆ handle_multi()

void handle_multi ( t_shell shell,
t_executor current 
)

Handles the execution of multiple commands.

This function initializes the t_info structure, executes a sequence of commands represented by the provided nodes of the executor list, and waits for their completion. It also makes a copie of the file descriptor for input redirection and restores it after completion. It handles errors returned from handle_pipeline().

Parameters
shellThe minishell main data structure.
currentThe head of the executor list representing a command.

◆ init_info()

t_info * init_info ( t_shell shell)

Initializes the t_info structure.

This function allocates memory for the t_info structure, stores process IDs for child processes, a copy of the standard input file descriptor, and a reference to the minishell main data structure.

Parameters
shellThe minishell main data structure.
Returns
A pointer to the initialized t_info structure.

◆ wait_pipeline()

void wait_pipeline ( t_info info,
int  number 
)

Wait for child processes to finish execution + update the exit code.

This function waits for the child processes created during command execution to finish and updates the exit code based on their exit status only if the exit status is not 79 (exit without argument). Then it frees the info struct and all it's allocated members.

Parameters
infoPointer to the t_info structure.
numberNumber of child processes to wait for.