diff --git a/srcs/.commands.c.swp b/srcs/.commands.c.swp new file mode 100644 index 0000000..94fa74e Binary files /dev/null and b/srcs/.commands.c.swp differ diff --git a/srcs/.exec.c.swp b/srcs/.exec.c.swp new file mode 100644 index 0000000..be3c813 Binary files /dev/null and b/srcs/.exec.c.swp differ diff --git a/srcs/exec.c b/srcs/exec.c index 18b9d8e..2159f76 100755 --- a/srcs/exec.c +++ b/srcs/exec.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */ -/* Updated: 2024/03/26 09:11:52 by marde-vr ### ########.fr */ +/* Updated: 2024/03/26 17:33:20 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -90,6 +90,8 @@ void exec_commands(t_msh *msh) } if (!g_return_code && WIFEXITED(status)) g_return_code = WEXITSTATUS(status); + if(WIFSIGNALED(status) && WTERMSIG(status) == SIGQUIT) + printf("Quit (core dumped)\n"); i = 0; while (i < cmd_count) { @@ -103,4 +105,5 @@ void exec_commands(t_msh *msh) msh->pids = 0; signal(SIGINT, signal_handler_interactive); signal(SIGQUIT, signal_handler_interactive); + set_echoctl(0); } diff --git a/srcs/here_doc.c b/srcs/here_doc.c index 1aa1427..cf43ebe 100644 --- 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/03/26 09:07:01 by marde-vr ### ########.fr */ +/* Updated: 2024/03/26 17:52:26 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,6 @@ void get_here_doc_input(t_msh *msh, char *eof) char *line; line = NULL; - signal(SIGINT, signal_handler_here_doc); while (1) { free(line); @@ -40,6 +39,7 @@ 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); + signal(SIGINT, signal_handler_here_doc); get_here_doc_input(msh, eof); close(msh->in_fd); free(here_doc_file); diff --git a/srcs/main.c b/srcs/main.c index 084ce82..3ed0347 100755 --- a/srcs/main.c +++ b/srcs/main.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */ -/* Updated: 2024/03/26 14:06:33 by tomoron ### ########.fr */ +/* Updated: 2024/03/26 17:25:20 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -107,9 +107,12 @@ int init_minishell(t_msh **msh, int argc, char **argv, char **envp) (void)argc; (void)argv; (*msh)->env = get_env(envp); + tcgetattr(1, &t_p); + (*msh)->echoctl = t_p.c_lflag & ECHOCTL; signal(SIGINT, signal_handler_interactive); signal(SIGQUIT, signal_handler_interactive); - t_p.c_lflag = t_p.c_lflag & (~ECHOCTL); + if(set_echoctl(0)) + ft_exit(*msh, 1); return (0); } @@ -135,6 +138,7 @@ int main(int argc, char **argv, char **envp) free_cmd(msh->cmds); } rl_clear_history(); + set_echoctl(msh->echoctl); free_msh(msh); ft_printf("exit\n"); return (g_return_code); diff --git a/srcs/minishell.h b/srcs/minishell.h index 3dbc39b..525d36d 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/03/26 09:07:38 by marde-vr ### ########.fr */ +/* Updated: 2024/03/26 17:13:30 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -60,6 +60,7 @@ typedef struct s_msh int in_fd; int out_fd; int locked_return_code; + int echoctl; } t_msh; extern int g_return_code; @@ -116,5 +117,6 @@ void *here_doc_variables(int write, int index, void *data); char *get_tmp_file_name(t_msh *msh); int contains_newline(char *str); void parse_var(t_msh *msh, char *line); +int set_echoctl(int value); #endif diff --git a/srcs/pipe.c b/srcs/pipe.c index e5a7867..ffb9d15 100644 --- a/srcs/pipe.c +++ b/srcs/pipe.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:17:25 by marde-vr #+# #+# */ -/* Updated: 2024/03/26 08:40:54 by marde-vr ### ########.fr */ +/* Updated: 2024/03/26 17:21:57 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,6 +45,7 @@ void execute_command(t_msh *msh, char **cmd_args, int i) } if (msh->cmds->token) { + set_echoctl(msh->echoctl); env = env_to_char_tab(msh->env); execve(msh->cmds->token, cmd_args, env); ft_free_str_arr(env); diff --git a/srcs/signal_handler.c b/srcs/signal_handler.c index 111caf1..4a72cea 100644 --- 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/03/26 08:42:47 by marde-vr ### ########.fr */ +/* Updated: 2024/03/26 17:59:37 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -53,9 +53,29 @@ void signal_handler_here_doc(int signum) ft_exit(msh, 1); } } +int set_echoctl(int value) +{ + struct termios t_p; + if(tcgetattr(1, &t_p)) + { + ft_printf_fd(2, "minishell: an error occured while setting the local fl\ +ags"); + return(1); + } + if(value) + t_p.c_lflag = t_p.c_lflag | ECHOCTL; + else + t_p.c_lflag = t_p.c_lflag & (~ECHOCTL); + if(tcsetattr(1, TCSANOW, &t_p)) + { + ft_printf_fd(2, "minishell: an error occured while setting the local fl\ + ags"); + return(1); + } + return(0); +} void signal_handler_command(int signum) { - if (signum == SIGQUIT) - printf("^\\Quit (core dumped)\n"); + (void)signum; } diff --git a/srcs/utils.c b/srcs/utils.c index dda5234..75f8acd 100644 --- 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/03/25 12:33:44 by tomoron ### ########.fr */ +/* Updated: 2024/03/26 17:23:51 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,7 @@ void free_msh(t_msh *msh) free(msh->pids); free(msh->fds); free_cmd(msh->cmds); + set_echoctl(msh->echoctl); free(msh); } }