diff --git a/srcs/.export.c.swp b/srcs/.export.c.swp deleted file mode 100644 index 35824f2..0000000 Binary files a/srcs/.export.c.swp and /dev/null differ diff --git a/srcs/exec.c b/srcs/exec.c deleted file mode 100755 index bfcb4c1..0000000 --- a/srcs/exec.c +++ /dev/null @@ -1,114 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* exec.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: marde-vr +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */ -/* Updated: 2024/04/18 20:48:52 by marde-vr ### ########.fr */ -/* */ -/* ************************************************************************** */ - -/* -#include "minishell.h" -#include - -int exec(t_msh *msh, char **cmd_args, int i, int cmd_count) -{ - pid_t pid; - - if (i != cmd_count - 1) - { - if (pipe(msh->fds[i]) == -1) - { - perror("pipe"); - ft_exit(msh, 1); - } - } - pid = fork(); - if (pid == -1) - { - perror("fork"); - ft_exit(msh, 1); - } - if (pid == 0) - child(msh, cmd_args, i); - else - { - parent(msh, i, cmd_count); - msh->pids[i] = pid; - free(cmd_args); - } - return (0); -} - -void exec_command(t_msh *msh, int i, int cmd_count) -{ - g_return_code = 0; - msh->fds[i] = ft_calloc(2, sizeof(int *)); - if (!msh->fds[i]) - ft_exit(msh, 1); - if (first_is_in_type(msh)) - { - get_in_type(msh, msh->tokens); - if (!g_return_code) - get_out_type(msh, msh->tokens); - } - else - { - get_out_type(msh, msh->tokens); - if (!g_return_code) - get_in_type(msh, msh->tokens); - } - if (!cmd_is_builtin(msh, msh->tokens->value)) - get_cmd_path(msh); - exec(msh, get_cmd_args(msh), i, cmd_count); - remove_command_from_msh(msh); -} - -void end_execution(t_msh *msh, int cmd_count) -{ - int i; - int status; - - i = 0; - while (i < cmd_count) - waitpid(msh->pids[i++], &status, 0); - 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) - { - free(msh->fds[i]); - msh->fds[i] = 0; - i++; - } - free(msh->fds); - msh->fds = 0; - free(msh->pids); - msh->pids = 0; - //signal(SIGINT, signal_handler_interactive); - signal(SIGQUIT, signal_handler_interactive); - set_echoctl(0); -} - -void exec_commands(t_msh *msh) -{ - int cmd_count; - int i; - - i = -1; - if (!msh->tokens) - return ; - cmd_count = get_cmd_count(msh->tokens); - msh->fds = ft_calloc(cmd_count, sizeof(int **)); - msh->pids = ft_calloc(cmd_count, sizeof(int *)); - if (!msh->pids || !msh->fds) - ft_exit(msh, 1); - while (++i < cmd_count) - exec_command(msh, i, cmd_count); - end_execution(msh, cmd_count); -}*/ diff --git a/srcs/here_doc.c b/srcs/here_doc.c index 42e6e13..ea0a71f 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/18 20:48:53 by marde-vr ### ########.fr */ +/* Updated: 2024/04/19 20:00:04 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,7 +40,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); + signal(SIGINT, signal_handler_here_doc); get_here_doc_input(msh, eof); close(msh->in_fd); printf("close2"); @@ -52,10 +52,10 @@ void here_doc_signal(t_msh *msh, int child_pid, char *here_doc_file) { int status; - //signal(SIGINT, signal_handler_command); + signal(SIGINT, signal_handler_command); signal(SIGQUIT, signal_handler_here_doc); waitpid(child_pid, &status, 0); - //signal(SIGINT, signal_handler_interactive); + signal(SIGINT, signal_handler_interactive); signal(SIGQUIT, signal_handler_interactive); close(msh->in_fd); printf("close 1\n"); diff --git a/srcs/main.c b/srcs/main.c index 0783daf..9c5bc3f 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/04/18 20:57:00 by marde-vr ### ########.fr */ +/* Updated: 2024/04/19 20:01:12 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -83,7 +83,7 @@ int init_minishell(t_msh **msh, int argc, char **argv, char **envp) (*msh)->env = get_env(envp); tcgetattr(1, &t_p); (*msh)->echoctl = t_p.c_lflag & ECHOCTL; - // signal(SIGINT, signal_handler_interactive); //enables ctrl-C + signal(SIGINT, signal_handler_interactive); //enables ctrl-C signal(SIGQUIT, signal_handler_interactive); if (set_echoctl(0)) ft_exit(*msh, 1); @@ -143,4 +143,6 @@ int main(int argc, char **argv, char **envp) exec_command_bonus(msh, commands); free(commands); } + printf("exit\n"); + return(g_return_code); } diff --git a/srcs/pipe.c b/srcs/pipe.c index 564e36d..b92deff 100755 --- 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/04/19 19:27:52 by marde-vr ### ########.fr */ +/* Updated: 2024/04/19 20:00:09 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -67,7 +67,7 @@ void child(t_msh *msh, char **cmd_args, int i) void parent(t_msh *msh, int i, int cmd_count) { - //signal(SIGINT, signal_handler_command); + signal(SIGINT, signal_handler_command); signal(SIGQUIT, signal_handler_command); if (i != 0) { diff --git a/todo_list b/todo_list index 00b2ec2..93633b9 100644 --- a/todo_list +++ b/todo_list @@ -1,9 +1,7 @@ -print message quand segfault et "(core dumped)" si WCOREDUMP + "(core dumped)" si WCOREDUMP export += export sort -fix exit | exit -exec export in fork when piped here doc in fork pipe with parenthesis