changement signaux et reactivation du echoctl quand exit
This commit is contained in:
BIN
srcs/.commands.c.swp
Normal file
BIN
srcs/.commands.c.swp
Normal file
Binary file not shown.
BIN
srcs/.exec.c.swp
Normal file
BIN
srcs/.exec.c.swp
Normal file
Binary file not shown.
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */
|
/* 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))
|
if (!g_return_code && WIFEXITED(status))
|
||||||
g_return_code = WEXITSTATUS(status);
|
g_return_code = WEXITSTATUS(status);
|
||||||
|
if(WIFSIGNALED(status) && WTERMSIG(status) == SIGQUIT)
|
||||||
|
printf("Quit (core dumped)\n");
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < cmd_count)
|
while (i < cmd_count)
|
||||||
{
|
{
|
||||||
@ -103,4 +105,5 @@ void exec_commands(t_msh *msh)
|
|||||||
msh->pids = 0;
|
msh->pids = 0;
|
||||||
signal(SIGINT, signal_handler_interactive);
|
signal(SIGINT, signal_handler_interactive);
|
||||||
signal(SIGQUIT, signal_handler_interactive);
|
signal(SIGQUIT, signal_handler_interactive);
|
||||||
|
set_echoctl(0);
|
||||||
}
|
}
|
||||||
|
@ -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/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;
|
char *line;
|
||||||
|
|
||||||
line = NULL;
|
line = NULL;
|
||||||
signal(SIGINT, signal_handler_here_doc);
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
free(line);
|
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, 0, msh);
|
||||||
here_doc_variables(1, 1, here_doc_file);
|
here_doc_variables(1, 1, here_doc_file);
|
||||||
|
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);
|
||||||
free(here_doc_file);
|
free(here_doc_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/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)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
(*msh)->env = get_env(envp);
|
(*msh)->env = get_env(envp);
|
||||||
|
tcgetattr(1, &t_p);
|
||||||
|
(*msh)->echoctl = t_p.c_lflag & ECHOCTL;
|
||||||
signal(SIGINT, signal_handler_interactive);
|
signal(SIGINT, signal_handler_interactive);
|
||||||
signal(SIGQUIT, 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);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,6 +138,7 @@ int main(int argc, char **argv, char **envp)
|
|||||||
free_cmd(msh->cmds);
|
free_cmd(msh->cmds);
|
||||||
}
|
}
|
||||||
rl_clear_history();
|
rl_clear_history();
|
||||||
|
set_echoctl(msh->echoctl);
|
||||||
free_msh(msh);
|
free_msh(msh);
|
||||||
ft_printf("exit\n");
|
ft_printf("exit\n");
|
||||||
return (g_return_code);
|
return (g_return_code);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
|
/* 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 in_fd;
|
||||||
int out_fd;
|
int out_fd;
|
||||||
int locked_return_code;
|
int locked_return_code;
|
||||||
|
int echoctl;
|
||||||
} t_msh;
|
} t_msh;
|
||||||
|
|
||||||
extern int g_return_code;
|
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);
|
char *get_tmp_file_name(t_msh *msh);
|
||||||
int contains_newline(char *str);
|
int contains_newline(char *str);
|
||||||
void parse_var(t_msh *msh, char *line);
|
void parse_var(t_msh *msh, char *line);
|
||||||
|
int set_echoctl(int value);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -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/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)
|
if (msh->cmds->token)
|
||||||
{
|
{
|
||||||
|
set_echoctl(msh->echoctl);
|
||||||
env = env_to_char_tab(msh->env);
|
env = env_to_char_tab(msh->env);
|
||||||
execve(msh->cmds->token, cmd_args, env);
|
execve(msh->cmds->token, cmd_args, env);
|
||||||
ft_free_str_arr(env);
|
ft_free_str_arr(env);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */
|
/* 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);
|
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)
|
void signal_handler_command(int signum)
|
||||||
{
|
{
|
||||||
if (signum == SIGQUIT)
|
(void)signum;
|
||||||
printf("^\\Quit (core dumped)\n");
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/05 18:19:26 by marde-vr #+# #+# */
|
/* 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->pids);
|
||||||
free(msh->fds);
|
free(msh->fds);
|
||||||
free_cmd(msh->cmds);
|
free_cmd(msh->cmds);
|
||||||
|
set_echoctl(msh->echoctl);
|
||||||
free(msh);
|
free(msh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user