From 923da71a49d38bad48ae418bbf13f3649ac7f0d7 Mon Sep 17 00:00:00 2001 From: tomoron Date: Mon, 6 May 2024 15:23:30 +0200 Subject: [PATCH] AAAAAAAAAAA --- srcs/exec_bonus.c | 12 ++++++------ srcs/here_doc.c | 3 ++- srcs/input_redirections.c | 2 +- srcs/minishell.h | 7 +++++-- srcs/output_redirections.c | 2 +- srcs/utils.c | 8 +++++--- 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/srcs/exec_bonus.c b/srcs/exec_bonus.c index 3a2b742..331fcaa 100755 --- a/srcs/exec_bonus.c +++ b/srcs/exec_bonus.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */ -/* Updated: 2024/05/06 14:25:19 by tomoron ### ########.fr */ +/* Updated: 2024/05/06 15:18:28 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -80,11 +80,9 @@ void exec_command(t_msh *msh, int i, int cmd_count) msh->fds[i] = ft_calloc(2, sizeof(int *)); if (!msh->fds[i]) ft_exit(msh, 1); - if (msh->tokens && !cmd_is_builtin(msh, msh->tokens->value) - && msh->in_fd != -1) + if (msh->tokens && !cmd_is_builtin(msh, msh->tokens->value) && msh->in_fd != -1) get_cmd_path(msh); - if (((msh->tokens && msh->tokens->value) || is_parenthesis(msh->cmds)) - && msh->in_fd != -1) + if (((msh->tokens && msh->tokens->value) || is_parenthesis(msh->cmds)) && msh->in_fd != -1) exec(msh, get_cmd_args(msh), i, cmd_count); else { @@ -92,6 +90,8 @@ void exec_command(t_msh *msh, int i, int cmd_count) close(msh->in_fd); if (msh->out_fd > 2) close(msh->out_fd); + if(!g_return_code) + g_return_code = 1; } } remove_command_from_msh(msh); @@ -106,7 +106,7 @@ void end_execution(t_msh *msh, int cmd_count) status = 0; while (i < cmd_count) waitpid(msh->pids[i++], &status, 0); - close_all_pipes(msh, cmd_count, i); + close_all_pipes(msh); if (!g_return_code && WIFEXITED(status)) g_return_code = WEXITSTATUS(status); if (WIFSIGNALED(status)) diff --git a/srcs/here_doc.c b/srcs/here_doc.c index 1b2e036..9e51b6f 100755 --- a/srcs/here_doc.c +++ b/srcs/here_doc.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/24 17:44:32 by marde-vr #+# #+# */ -/* Updated: 2024/04/26 13:15:24 by marde-vr ### ########.fr */ +/* Updated: 2024/05/06 15:09:44 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -44,6 +44,7 @@ void here_doc_child(t_msh *msh, char *eof) signal(SIGQUIT, SIG_IGN); get_here_doc_input(msh, eof); close(msh->in_fd); + close_all_pipes(msh); ft_exit(msh, 0); } diff --git a/srcs/input_redirections.c b/srcs/input_redirections.c index 0354990..3c29015 100755 --- a/srcs/input_redirections.c +++ b/srcs/input_redirections.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:15:27 by marde-vr #+# #+# */ -/* Updated: 2024/05/06 14:14:21 by tomoron ### ########.fr */ +/* Updated: 2024/05/06 14:43:48 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/srcs/minishell.h b/srcs/minishell.h index f6d237b..1f82001 100755 --- a/srcs/minishell.h +++ b/srcs/minishell.h @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */ -/* Updated: 2024/05/06 14:27:14 by tomoron ### ########.fr */ +/* Updated: 2024/05/06 15:17:14 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -98,7 +98,6 @@ void redirect_output(t_msh *msh, int i, char **cmd_args); void redirect_input(t_msh *msh, int i, char **cmd_args); void print_syntax_error_bonus(t_cmd *cmd, t_cmd *cmds); int filename_corresponds(char *wildcard, char *value); -void close_all_pipes(t_msh *msh, int cmd_count, int i); t_token *parse_cmds_to_token(t_cmd *command, t_env *env); int ft_export(t_msh *msh, t_token *cmd, t_env *env); void print_env_declare(t_msh *msh, t_env *env_orig); @@ -139,12 +138,15 @@ int get_normal_cmd_len(char *cmd); t_cmd *get_next_command(t_cmd *cmd); int get_args_count(t_token *cmds); char **env_to_char_tab(t_env *env); +int get_token_len(char *command); int first_is_in_type(t_cmd *cmd); void print_msh_struct(t_msh *msh); int get_next_arg_len(char *cmd); int check_str_syntax(char *cmd); +void close_all_pipes(t_msh *msh); int is_operand_type(t_cmd *cmd); int contains_newline(char *str); +t_token *free_token(t_token *token); int get_cmd_count(t_cmd *cmds); int check_var_name(char *name); char **get_cmd_args(t_msh *msh); @@ -153,6 +155,7 @@ int is_parenthesis(t_cmd *cmd); int is_output_type(t_cmd *cmd); int is_parenthesis(t_cmd *cmd); void print_signaled(int status); +void exec_commands(t_msh *msh); int is_input_type(t_cmd *cmd); char *remove_path(char *token); t_cmd *parsing_bonus(char *cmd); diff --git a/srcs/output_redirections.c b/srcs/output_redirections.c index 39a16d2..94dc8c7 100755 --- a/srcs/output_redirections.c +++ b/srcs/output_redirections.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/19 14:09:44 by tomoron #+# #+# */ -/* Updated: 2024/05/06 10:28:56 by tomoron ### ########.fr */ +/* Updated: 2024/05/06 14:43:45 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/srcs/utils.c b/srcs/utils.c index 1f1996c..87fce37 100755 --- a/srcs/utils.c +++ b/srcs/utils.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:19:26 by marde-vr #+# #+# */ -/* Updated: 2024/04/30 14:03:28 by marde-vr ### ########.fr */ +/* Updated: 2024/05/06 15:17:37 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -74,10 +74,12 @@ int file_access(t_msh *msh, int *found) return (1); } -void close_all_pipes(t_msh *msh, int cmd_count, int i) +void close_all_pipes(t_msh *msh) { + int i; + i = 0; - while (i < cmd_count) + while (msh->fds[i]) { close_pipe_fds(msh, i); i++;