exit status at the end of the executor_execute_pipeline

This commit is contained in:
whaffman 2025-02-18 16:00:38 +01:00
parent 0784d3cf04
commit c368cf80ea
5 changed files with 23 additions and 15 deletions

View File

@ -6,7 +6,7 @@
/* By: willem <willem@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/08 17:06:07 by willem #+# #+# */
/* Updated: 2025/02/13 14:57:13 by whaffman ######## odam.nl */
/* Updated: 2025/02/18 15:45:27 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -17,9 +17,9 @@
char *executor_absolute_path(t_list *env, char *cmd);
void executor_child(t_command *command);
int executor_fork(t_command *command);
pid_t executor_fork(t_command *command);
void executor_create_pipes(t_minishell *minishell);
void executor_execute_pipeline(t_minishell *minishell);
int executor_execute_pipeline(t_minishell *minishell);
void executor_close_fds(int n_fds);

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/05 12:36:08 by whaffman #+# #+# */
/* Updated: 2025/02/13 14:27:07 by whaffman ######## odam.nl */
/* Updated: 2025/02/18 14:34:39 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */

View File

@ -6,24 +6,29 @@
/* By: willem <willem@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/12 21:25:02 by willem #+# #+# */
/* Updated: 2025/02/13 15:04:18 by whaffman ######## odam.nl */
/* Updated: 2025/02/18 15:59:43 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
void executor_execute_pipeline(t_minishell *minishell)
int executor_execute_pipeline(t_minishell *minishell)
{
t_list *current;
t_command *command;
pid_t last_pid;
int exit_status;
executor_create_pipes(minishell);
current = minishell->commands;
last_pid = 0;
while (current)
{
command = (t_command *)current->content;
command->environment = minishell->environment;
executor_fork(command);
last_pid = executor_fork(command);
current = current->next;
}
waitpid(last_pid, &exit_status, 0);
return (((exit_status) & 0xff00) >> 8);
}

View File

@ -6,16 +6,16 @@
/* By: willem <willem@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/12 21:24:52 by willem #+# #+# */
/* Updated: 2025/02/13 15:03:19 by whaffman ######## odam.nl */
/* Updated: 2025/02/18 15:41:56 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
int executor_fork(t_command *command)
pid_t executor_fork(t_command *command)
{
pid_t pid;
int status;
// int status;
pid = fork();
if (pid > 0)
@ -24,12 +24,12 @@ int executor_fork(t_command *command)
close(command->fd_in);
if (command->fd_out != 1)
close(command->fd_out);
waitpid(pid, &status, 0);
return (((status) & 0xff00) >> 8);
// waitpid(pid, &status, 0);
// return (((status) & 0xff00) >> 8);
}
else if (pid == 0)
executor_child(command);
else
perror("fork");
return (-1);
return (pid);
}

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/05 16:21:39 by whaffman #+# #+# */
/* Updated: 2025/02/12 20:25:23 by willem ######## odam.nl */
/* Updated: 2025/02/18 15:49:36 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -95,7 +95,10 @@ void simple_builtins(t_minishell *minishell)
else if (cmp_value(minishell->tokens, "export"))
builtin_export(minishell);
else if (cmp_value(minishell->tokens, "unset"))
environment_del(&(minishell->environment), ((t_token *)minishell->tokens->next->content)->value);
{
environment_del(&(minishell->environment),
((t_token *)minishell->tokens->next->content)->value);
}
else
{
executor_execute_pipeline(minishell);