From e2898b81288eaa835264c6ca5b92c42abead5212 Mon Sep 17 00:00:00 2001 From: tomoron Date: Fri, 19 Apr 2024 20:10:10 +0200 Subject: [PATCH] signaux et d'autres trucs mais flemme de le marque ducoup je mets un message de commit plus long pour le dire --- srcs/.export.c.swp | Bin 12288 -> 0 bytes srcs/exec.c | 114 --------------------------------------------- srcs/here_doc.c | 8 ++-- srcs/main.c | 6 ++- srcs/pipe.c | 4 +- todo_list | 4 +- 6 files changed, 11 insertions(+), 125 deletions(-) delete mode 100644 srcs/.export.c.swp delete mode 100755 srcs/exec.c diff --git a/srcs/.export.c.swp b/srcs/.export.c.swp deleted file mode 100644 index 35824f23475e6b91f4fe7d4c3babf6f3a9081704..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2&ubiI7{}jgtsQGrDitjVZ+5ZS?2pW5o6uy^4Pvdfhhh4QkJMVVK%+4+| zv)hDJq@|whK@kN-yh%@Ly-EdbQP6|Og2(;?UIZ(6(C_okuWYihRdcZNPWkM-Kfm+5 z-{*Y?LT9P^((w~~cB0B~J;KGWLD z786Z>_;5Wq({a3}FZASoQuskfkDsGID}v>))79IK=L9X`x_aO@0$r?hJAOFP7%r+> zl>^Fw+dI$;o0XXncCa=nk9s~g${*dkaQk^`gmOSRpd3&RCg1IhvAfO0@Npd3&RCNJ{Qdv=!;HNOM!?mF&<^&4??)J00b}6CgN(fiE`m02!Ex|BFu)=31lR}u z*u&U0@FjQ~Tmq}04?+-td2kr)1;0PQ*bm?gWq;D_A~eqd;~rKm%suz2A%^)!Q~d;`7)m%%6CeefPQ56%J`ybN9hRq!O( z4@LmxP3G<{+373ZNTm|arr8@c-IQh&g)Fm<8S?V2^C6G z5;2y708Pub%_Xa`Ona^}kCrlzJjuM2B@D-AfopcJTd@2yyu@AMMTteBRKk*_v*=qy z!z(g9$qJ(H4Nb>`mSdZaExgcaI>INZ=!xS}OJ;OEZq(MC%&md(E9o75zeMcL8h zfGD8e5@L!}s^uXe#c52U;s*}!v^-kpWA!l-M8I)sHT0sG9?y7FVRdUvu8+fmHdBlS9$xyVi~om2`D^Jt4`MVXPbMsB1P zgpcwTXFW>8ro*0OX_6w7=awX8B{aLe5DuG7yO0|*xYr4>y<`@7mc>(EuFPwjCLoq! z&AIerR0DgMK14P6=~y6oEp5GBq9Y=OH=Y*S+^`$=;Wv9#QFEM)W+4~nf>&1fQ-KUS z8XT_|3du`I=5OPS`l%eIEr0)Jhv-4N%(SH&6Q9GS8X0!IuvD z#*-Ju=6xi06)(y`Ebn*?w}-QyxjNCxF{T%Jaoa9l)Jbp~uS9U6Yg?hP4PL9(ru6ER zJ~_)LXN~D;V{(Qst@8Lg=IqJ&d>$42$_w8`$6blw5nrqqtm)91oH1&%My*PMZOgYs zrJqbAtr96Fw^)w4iq6=OBN-&eoN|E5U9TXfo Go&5 +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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