diff --git a/srcs/exec_bonus.c b/srcs/exec_bonus.c index 2fd2559..8d6e32c 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/04/23 16:32:16 by tomoron ### ########.fr */ +/* Updated: 2024/04/23 17:01:43 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -186,6 +186,12 @@ void end_execution(t_msh *msh, int cmd_count) g_return_code = WEXITSTATUS(status); if (WIFSIGNALED(status)) print_signaled(status); + if(msh->here_doc_filename) + { + unlink(msh->here_doc_filename) + free(msh->here_doc_filename); + msh->here_doc_filename = 0; + { free(msh->pids); free_fds(msh); msh->pids = 0; diff --git a/srcs/here_doc.c b/srcs/here_doc.c index c11e8d4..83fffd7 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/23 16:41:42 by tomoron ### ########.fr */ +/* Updated: 2024/04/23 16:59:17 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,13 +38,10 @@ void get_here_doc_input(t_msh *msh, char *eof) void here_doc_child(t_msh *msh, char *eof, char *here_doc_file) { - here_doc_variables(1, 0, msh); - here_doc_variables(1, 1, here_doc_file); + here_doc_variables(1, msh); signal(SIGINT, signal_handler_here_doc); get_here_doc_input(msh, eof); close(msh->in_fd); - printf("close2"); - free(here_doc_file); ft_exit(msh, 0); } @@ -58,11 +55,9 @@ void here_doc_signal(t_msh *msh, int child_pid, char *here_doc_file) signal(SIGINT, signal_handler_interactive); signal(SIGQUIT, signal_handler_interactive); close(msh->in_fd); - printf("close 1\n"); if (WIFEXITED(status) && WEXITSTATUS(status)) unlink(here_doc_file); msh->in_fd = open(here_doc_file, O_RDWR, 0644); - free(here_doc_file); if (msh->in_fd == -1 && !(WIFEXITED(status) && WEXITSTATUS(status))) perror("open"); } @@ -73,6 +68,7 @@ void handle_here_doc(t_msh *msh, char *eof) int pid; here_doc_file = get_tmp_file_name(msh); + msh->here_doc_filename = here_doc_file; msh->in_fd = open(here_doc_file, O_CREAT | O_RDWR, 0644); if (msh->in_fd == -1) { diff --git a/srcs/minishell.h b/srcs/minishell.h index 87ddb65..feeb3da 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/04/23 16:31:56 by tomoron ### ########.fr */ +/* Updated: 2024/04/23 16:52:15 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -73,6 +73,7 @@ typedef struct s_msh int out_fd; int locked_return_code; int echoctl; + char *here_doc_filename; } t_msh; extern int g_return_code; diff --git a/srcs/signal_handler.c b/srcs/signal_handler.c index 6b29482..9c7ab00 100755 --- a/srcs/signal_handler.c +++ b/srcs/signal_handler.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */ -/* Updated: 2024/04/22 19:53:34 by marde-vr ### ########.fr */ +/* Updated: 2024/04/23 16:59:02 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,29 +26,26 @@ void signal_handler_interactive(int signum) printf("%s%s", rl_prompt, rl_line_buffer); } -void *here_doc_variables(int write, int index, void *data) +void *here_doc_variables(int write, void *data) { - static void *variables[2]; + static void *variable; if (write) - variables[index] = data; + variables = data; else - return (variables[index]); + return (variables); return (0); } void signal_handler_here_doc(int signum) { t_msh *msh; - char *here_doc_file; if (signum == SIGINT) { printf("%s%s^C\n", rl_prompt, rl_line_buffer); - msh = here_doc_variables(0, 0, 0); - here_doc_file = here_doc_variables(0, 1, 0); + msh = here_doc_variables(0, 0); close(msh->in_fd); - free(here_doc_file); ft_exit(msh, 1); } } diff --git a/srcs/utils.c b/srcs/utils.c index f11cfa5..3577c66 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/23 16:41:42 by tomoron ### ########.fr */ +/* Updated: 2024/04/23 16:58:07 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,6 +38,7 @@ void free_msh(t_msh *msh) free(msh->pids); free_cmd(msh->cmds_head); free_fds(msh); + free(msh->here_doc_filename); free_token(msh->tokens); free(msh); }