21 #include "get_next_line.h"
39 dup2(pipe_fd[1], STDOUT_FILENO);
66 dup2(pipe_fd[0], STDIN_FILENO);
91 waitpid(left_pid, &status, 0);
92 waitpid(right_pid, &status, 0);
93 if (WIFEXITED(status))
94 right_status = WEXITSTATUS(status);
95 else if (WIFSIGNALED(status))
97 if (WTERMSIG(status) == SIGINT)
98 ft_putchar_fd(
'\n', STDERR_FILENO);
99 else if (WTERMSIG(status) == SIGQUIT)
100 ft_putstr_fd(
"Quit (core dumped)\n", STDERR_FILENO);
101 right_status = 128 + WTERMSIG(status);
105 return (right_status);
125 if (pipe(pipe_fd) == -1)
126 return (perror(
"minishell: pipe"), 1);
AST node creation and destruction prototypes.
void free_ast(t_ast *node)
Recursively free an entire AST tree.
Environment variable management prototypes.
void free_env_list(t_env **env_list)
Free all nodes in the env linked list.
int pipe_fork_error(int pipe_fd[2], pid_t left_pid)
Clean up pipe fds and wait for left child on fork failure.
int executor(t_ast *node, t_shell *shell)
Main AST executor that dispatches by node type.
Executor prototypes for commands, pipes, redirections & heredocs.
static int wait_for_pipe_children(pid_t left_pid, pid_t right_pid)
Wait for both pipe children and return the right one's status.
void exec_left_pipe_child(t_ast *left, int pipe_fd[2], t_shell *shell)
Execute the left side of a pipe in a child process.
int handle_pipe(t_ast *node, t_shell *shell)
Execute a pipe node by forking left and right children.
void exec_right_pipe_child(t_ast *right, int pipe_fd[2], t_shell *shell)
Execute the right side of a pipe in a child process.
void reset_child_signals(void)
Reset signals to default behavior for the child processes.
Signal handler prototypes.
t_ast_data data
cmd, redir or binary data
struct s_ast * left
left child (before pipe)
struct s_ast * right
right child (after pipe)
t_env * env
Environment linked list.
int is_child
Child flag (to avoid leaks)
char * current_input
Current input line.
struct s_ast * current_ast
Currently executing AST.