executo builtin fix?
This commit is contained in:
parent
029c3cbcb0
commit
5fc09400cd
@ -6,7 +6,7 @@
|
|||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/02/05 12:36:08 by whaffman #+# #+# */
|
/* Created: 2025/02/05 12:36:08 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/02/26 17:26:27 by whaffman ######## odam.nl */
|
/* Updated: 2025/03/04 15:25:16 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ typedef struct s_command
|
|||||||
{
|
{
|
||||||
char *command;
|
char *command;
|
||||||
char **args;
|
char **args;
|
||||||
t_list *environment;
|
// t_list *environment;
|
||||||
t_list *redirect_in;
|
t_list *redirect_in;
|
||||||
t_list *redirect_out;
|
t_list *redirect_out;
|
||||||
int fd_in;
|
int fd_in;
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/02/20 11:12:38 by whaffman #+# #+# */
|
/* Created: 2025/02/20 11:12:38 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/03/03 14:38:52 by whaffman ######## odam.nl */
|
/* Updated: 2025/03/04 15:28:59 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -25,6 +25,6 @@ int builtin_router(t_minishell *msh, t_command *cmd)
|
|||||||
|
|
||||||
if (!is_builtin(cmd->args[0]))
|
if (!is_builtin(cmd->args[0]))
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
msh->exit_status = builtin_fn[is_builtin(cmd->args[0])](msh, cmd);
|
return (builtin_fn[is_builtin(cmd->args[0])](msh, cmd));
|
||||||
return (TRUE);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/02/20 11:03:33 by whaffman #+# #+# */
|
/* Created: 2025/02/20 11:03:33 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/02/26 14:42:49 by whaffman ######## odam.nl */
|
/* Updated: 2025/03/04 15:45:38 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -25,5 +25,5 @@ int is_builtin(char *cmd)
|
|||||||
return (i);
|
return (i);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return (FALSE);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/02/05 16:21:39 by whaffman #+# #+# */
|
/* Created: 2025/02/05 16:21:39 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/02/26 16:08:49 by whaffman ######## odam.nl */
|
/* Updated: 2025/03/04 15:43:53 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -16,6 +16,5 @@ void simple_builtins(t_minishell *msh)
|
|||||||
{
|
{
|
||||||
if (msh->commands == NULL)
|
if (msh->commands == NULL)
|
||||||
return ;
|
return ;
|
||||||
if (!builtin_router(msh, msh->commands->content))
|
|
||||||
executor_execute_pipeline(msh);
|
executor_execute_pipeline(msh);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: marvin <marvin@student.42.fr> +#+ */
|
/* By: marvin <marvin@student.42.fr> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/02/18 20:06:37 by qmennen #+# #+# */
|
/* Created: 2025/02/18 20:06:37 by qmennen #+# #+# */
|
||||||
/* Updated: 2025/02/23 12:43:35 by Quinten ######## odam.nl */
|
/* Updated: 2025/03/04 15:49:58 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -32,6 +32,8 @@ void print_commands(void *param)
|
|||||||
ft_lstiter(command->redirect_in, print_redirects);
|
ft_lstiter(command->redirect_in, print_redirects);
|
||||||
printf("-- Output redirects:\n");
|
printf("-- Output redirects:\n");
|
||||||
ft_lstiter(command->redirect_out, print_redirects);
|
ft_lstiter(command->redirect_out, print_redirects);
|
||||||
|
printf("-- fd_in: %i\n", command->fd_in);
|
||||||
|
printf("-- fd_out: %i\n", command->fd_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_redirects(void *param)
|
void print_redirects(void *param)
|
||||||
|
|||||||
@ -6,32 +6,59 @@
|
|||||||
/* By: willem <willem@student.codam.nl> +#+ */
|
/* By: willem <willem@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/02/12 21:25:02 by willem #+# #+# */
|
/* Created: 2025/02/12 21:25:02 by willem #+# #+# */
|
||||||
/* Updated: 2025/02/26 17:42:46 by whaffman ######## odam.nl */
|
/* Updated: 2025/03/04 16:03:29 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
|
static int execute_builtin(t_minishell *msh, t_command *cmd)
|
||||||
|
{
|
||||||
|
int original_stdout;
|
||||||
|
int original_stdin;
|
||||||
|
int exit_status;
|
||||||
|
|
||||||
|
original_stdin = dup(STDIN_FILENO);
|
||||||
|
original_stdout = dup(STDOUT_FILENO);
|
||||||
|
dup2(cmd->fd_in, STDIN_FILENO);
|
||||||
|
dup2(cmd->fd_out, STDOUT_FILENO);
|
||||||
|
signal_init_child();
|
||||||
|
exit_status = builtin_router(msh, cmd);
|
||||||
|
signal_init_minishell();
|
||||||
|
close(cmd->fd_in);
|
||||||
|
close(cmd->fd_out);
|
||||||
|
dup2(original_stdin, STDIN_FILENO);
|
||||||
|
dup2(original_stdout, STDOUT_FILENO);
|
||||||
|
close(original_stdin);
|
||||||
|
close(original_stdout);
|
||||||
|
return (exit_status);
|
||||||
|
}
|
||||||
|
|
||||||
int executor_execute_pipeline(t_minishell *msh)
|
int executor_execute_pipeline(t_minishell *msh)
|
||||||
{
|
{
|
||||||
t_list *current;
|
t_list *current;
|
||||||
t_command *command;
|
|
||||||
pid_t last_pid;
|
pid_t last_pid;
|
||||||
int exit_status;
|
int exit_status;
|
||||||
|
|
||||||
executor_create_pipes(msh);
|
executor_create_pipes(msh);
|
||||||
executor_create_redirects(msh);
|
executor_create_redirects(msh);
|
||||||
current = msh->commands;
|
current = msh->commands;
|
||||||
|
ft_lstiter(current, print_commands);
|
||||||
last_pid = 0;
|
last_pid = 0;
|
||||||
while (current)
|
while (current)
|
||||||
{
|
{
|
||||||
command = (t_command *)current->content;
|
if (is_builtin(((t_command *)current->content)->command) >= 0)
|
||||||
command->environment = msh->environment;
|
msh->exit_status = execute_builtin(msh,
|
||||||
last_pid = executor_fork(msh, command);
|
(t_command *)current->content);
|
||||||
|
else
|
||||||
|
last_pid = executor_fork(msh, (t_command *)current->content);
|
||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
|
if (last_pid != 0)
|
||||||
|
{
|
||||||
waitpid(last_pid, &exit_status, 0);
|
waitpid(last_pid, &exit_status, 0);
|
||||||
msh->exit_status = ((exit_status) & 0xff00) >> 8;
|
msh->exit_status = ((exit_status) & 0xff00) >> 8;
|
||||||
signal_init_minishell();
|
}
|
||||||
return (((exit_status) & 0xff00) >> 8);
|
signal_init_minishell();
|
||||||
|
return (msh->exit_status);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* :::::::: */
|
/* :::::::: */
|
||||||
/* parser_new_command.c :+: :+: */
|
/* parser_alloc_command.c :+: :+: */
|
||||||
/* +:+ */
|
/* +:+ */
|
||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/02/11 16:18:21 by qmennen #+# #+# */
|
/* Created: 2025/02/11 16:18:21 by qmennen #+# #+# */
|
||||||
/* Updated: 2025/02/26 16:14:31 by whaffman ######## odam.nl */
|
/* Updated: 2025/03/04 15:41:59 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ t_command *parser_alloc_command(t_minishell *msh, char *cmd)
|
|||||||
command->fd_out = 1;
|
command->fd_out = 1;
|
||||||
command->redirect_in = NULL;
|
command->redirect_in = NULL;
|
||||||
command->redirect_out = NULL;
|
command->redirect_out = NULL;
|
||||||
command->environment = NULL;
|
// command->environment = NULL;
|
||||||
command->n_fds = 0;
|
command->n_fds = 0;
|
||||||
command->command = cmd;
|
command->command = cmd;
|
||||||
return (command);
|
return (command);
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* :::::::: */
|
||||||
/* parser_get_commands.c :+: :+: :+: */
|
/* parser_get_commands.c :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ */
|
||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/02/11 14:06:02 by qmennen #+# #+# */
|
/* Created: 2025/02/11 14:06:02 by qmennen #+# #+# */
|
||||||
/* Updated: 2025/02/27 16:07:54 by qmennen ### ########.fr */
|
/* Updated: 2025/03/04 15:53:59 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -41,6 +41,5 @@ t_list *parser_get_commands(t_minishell *msh)
|
|||||||
if (current && ((t_token *)current->content)->type >= 3)
|
if (current && ((t_token *)current->content)->type >= 3)
|
||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
ft_lstiter(command_list, print_commands);
|
|
||||||
return (command_list);
|
return (command_list);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user