Commit 5349b6e5 authored by abenoit's avatar abenoit
Browse files

interupt signal fix

parent a9a5022a
......@@ -24,6 +24,7 @@ SRC += parent_process.c
SRC += launch_command.c
SRC += redirs.c
SRC += exec_utils.c
SRC += exec_utils_2.c
SRC += ft_echo.c
SRC += options.c
......
......@@ -6,7 +6,7 @@
/* By: mvidal-a <mvidal-a@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/11 16:49:21 by mvidal-a #+# #+# */
/* Updated: 2021/02/11 18:57:12 by abenoit ### ########.fr */
/* Updated: 2021/02/14 22:07:17 by abenoit ### ########.fr */
/* */
/* ************************************************************************** */
......@@ -42,6 +42,8 @@ typedef int (*t_exec)(char **args, t_xe *xe);
** main function
*/
int handle_exec_return(t_xe *xe, int fd_in, int proc);
int handle_execution(t_xe *xe, int fd_in, int proc);
int parent_pipe_end(t_command *cur_command, t_xe *xe,
......
......@@ -6,7 +6,7 @@
/* By: abenoit <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/11 17:52:41 by abenoit #+# #+# */
/* Updated: 2021/02/11 18:13:54 by abenoit ### ########.fr */
/* Updated: 2021/02/14 22:06:43 by abenoit ### ########.fr */
/* */
/* ************************************************************************** */
......@@ -57,12 +57,7 @@ int handle_pipe(t_command *cur_command, t_xe *xe, int fd_in, int proc)
if (close(fd[1]) == ERROR || close(fd_in) == ERROR)
return (FD_ERROR);
free_command(cur_command);
if (!(xe->flags & INTERUPT))
return (handle_execution(xe, fd[0], proc + 1));
else {
xe->flags = RUN;
return (SUCCESS);
}
return (handle_exec_return(xe, fd[0], proc + 1));
}
}
......@@ -77,12 +72,7 @@ int handle_command(t_command *cur_command, t_xe *xe,
free_command(cur_command);
dup2(xe->backup_stdout, STDOUT_FILENO);
dup2(xe->backup_stdin, STDIN_FILENO);
if (!(xe->flags & INTERUPT))
return (handle_execution(xe, STDIN_FILENO, 0));
else {
xe->flags = RUN;
return (SUCCESS);
}
return (handle_exec_return(xe, STDIN_FILENO, 0));
}
else if (cur_command->pipe_flag == TRUE)
{
......@@ -106,12 +96,7 @@ static int check_redir_type(t_command *cur_command, t_xe *xe,
dup2(xe->backup_stdout, STDOUT_FILENO);
dup2(xe->backup_stdin, STDIN_FILENO);
xe->stat_loc = 1;
if (!(xe->flags & INTERUPT))
return (handle_execution(xe, fd_in, proc));
else {
xe->flags = RUN;
return (SUCCESS);
}
return (handle_exec_return(xe, fd_in, proc));
}
if (cur_command->args == NULL)
{
......@@ -122,12 +107,7 @@ static int check_redir_type(t_command *cur_command, t_xe *xe,
return (FD_ERROR);
}
free_command(cur_command);
if (!(xe->flags & INTERUPT))
return (handle_execution(xe, fd_in, proc));
else {
xe->flags = RUN;
return (SUCCESS);
}
return (handle_exec_return(xe, fd_in, proc));
}
return (KEEP_ON);
}
......
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* exec_utils_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abenoit <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/14 22:03:15 by abenoit #+# #+# */
/* Updated: 2021/02/14 22:05:46 by abenoit ### ########.fr */
/* */
/* ************************************************************************** */
#include "parsing.h"
#include "execution.h"
int handle_exec_return(t_xe *xe, int fd_in, int proc)
{
if (!(xe->flags & INTERUPT))
return (handle_execution(xe, fd_in, proc));
else
{
xe->flags = RUN;
return (SUCCESS);
}
}
......@@ -6,7 +6,7 @@
/* By: abenoit <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/11 18:10:57 by abenoit #+# #+# */
/* Updated: 2021/02/11 18:14:59 by abenoit ### ########.fr */
/* Updated: 2021/02/14 22:44:43 by abenoit ### ########.fr */
/* */
/* ************************************************************************** */
......@@ -23,6 +23,7 @@ static int signal_interupt(t_xe *xe)
}
else if (xe->stat_loc == SIGINT)
{
xe->flags += INTERUPT;
if (ft_putstr_fd("\n", STDERR_FILENO) != WRITE_SUCCESS)
return (WRITE_ERR);
}
......@@ -36,6 +37,8 @@ static int parent_wait(t_xe *xe, int proc)
int ret;
i = 0;
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
while (i < proc)
{
ret = wait(&xe->stat_loc);
......@@ -51,6 +54,7 @@ static int parent_wait(t_xe *xe, int proc)
xe->stat_loc = WEXITSTATUS(xe->stat_loc);
i++;
}
signal_handler();
return (SUCCESS);
}
......@@ -98,12 +102,6 @@ int parent_pipe_end(t_command *cur_command, t_xe *xe,
ft_error(ret, xe);
if (ret == EXIT_ARG_ERR)
return (SUCCESS);
if (!(xe->flags & INTERUPT))
return (handle_execution(xe, STDIN_FILENO, 0));
else
{
xe->flags = RUN;
return (SUCCESS);
}
return (handle_exec_return(xe, STDIN_FILENO, 0));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment