changement signaux et reactivation du echoctl quand exit

This commit is contained in:
2024-03-27 14:30:32 +01:00
parent ca90a5f692
commit dad89c923e
9 changed files with 42 additions and 11 deletions

BIN
srcs/.commands.c.swp Normal file

Binary file not shown.

BIN
srcs/.exec.c.swp Normal file

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
}

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}
}