/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   executor_execute_pipeline.c                        :+:    :+:            */
/*                                                     +:+                    */
/*   By: willem <willem@student.codam.nl>             +#+                     */
/*                                                   +#+                      */
/*   Created: 2025/02/12 21:25:02 by willem        #+#    #+#                 */
/*   Updated: 2025/02/26 17:42:46 by whaffman      ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include "minishell.h"

int	executor_execute_pipeline(t_minishell *msh)
{
	t_list		*current;
	t_command	*command;
	pid_t		last_pid;
	int			exit_status;

	executor_create_pipes(msh);
	executor_create_redirects(msh);
	current = msh->commands;
	last_pid = 0;
	while (current)
	{
		command = (t_command *)current->content;
		command->environment = msh->environment;
		last_pid = executor_fork(msh, command);
		current = current->next;
	}
	waitpid(last_pid, &exit_status, 0);
	msh->exit_status = ((exit_status) & 0xff00) >> 8;
	signal_init_minishell();
	return (((exit_status) & 0xff00) >> 8);
}
