signaux et d'autres trucs mais flemme de le marque ducoup je mets un message de commit plus long pour le dire

This commit is contained in:
2024-04-19 20:10:10 +02:00
parent dfa81cd19c
commit e2898b8128
6 changed files with 11 additions and 125 deletions

Binary file not shown.

View File

@ -1,114 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* exec.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */
/* Updated: 2024/04/18 20:48:52 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */
/*
#include "minishell.h"
#include <sys/wait.h>
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);
}*/

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/24 17:44:32 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, 0, msh);
here_doc_variables(1, 1, here_doc_file); 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); get_here_doc_input(msh, eof);
close(msh->in_fd); close(msh->in_fd);
printf("close2"); printf("close2");
@ -52,10 +52,10 @@ void here_doc_signal(t_msh *msh, int child_pid, char *here_doc_file)
{ {
int status; int status;
//signal(SIGINT, signal_handler_command); signal(SIGINT, signal_handler_command);
signal(SIGQUIT, signal_handler_here_doc); signal(SIGQUIT, signal_handler_here_doc);
waitpid(child_pid, &status, 0); waitpid(child_pid, &status, 0);
//signal(SIGINT, signal_handler_interactive); signal(SIGINT, signal_handler_interactive);
signal(SIGQUIT, signal_handler_interactive); signal(SIGQUIT, signal_handler_interactive);
close(msh->in_fd); close(msh->in_fd);
printf("close 1\n"); printf("close 1\n");

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */ /* 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); (*msh)->env = get_env(envp);
tcgetattr(1, &t_p); tcgetattr(1, &t_p);
(*msh)->echoctl = t_p.c_lflag & ECHOCTL; (*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); signal(SIGQUIT, signal_handler_interactive);
if (set_echoctl(0)) if (set_echoctl(0))
ft_exit(*msh, 1); ft_exit(*msh, 1);
@ -143,4 +143,6 @@ int main(int argc, char **argv, char **envp)
exec_command_bonus(msh, commands); exec_command_bonus(msh, commands);
free(commands); free(commands);
} }
printf("exit\n");
return(g_return_code);
} }

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:17:25 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) 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); signal(SIGQUIT, signal_handler_command);
if (i != 0) if (i != 0)
{ {

View File

@ -1,9 +1,7 @@
print message quand segfault et "(core dumped)" si WCOREDUMP "(core dumped)" si WCOREDUMP
export += export +=
export sort export sort
fix exit | exit
exec export in fork when piped
here doc in fork here doc in fork
pipe with parenthesis pipe with parenthesis