signaux here_doc
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */
|
||||
/* Updated: 2024/04/26 10:34:15 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/04/26 10:48:31 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -72,6 +72,7 @@ int exec(t_msh *msh, char **cmd_args, int i, int cmd_count)
|
||||
|
||||
void exec_command(t_msh *msh, int i, int cmd_count)
|
||||
{
|
||||
get_redirections(msh, msh->cmds);
|
||||
g_return_code = 0;
|
||||
if(msh->out_fd != -1 && msh->in_fd != -1)
|
||||
{
|
||||
@ -111,7 +112,6 @@ void end_execution(t_msh *msh, int cmd_count)
|
||||
free(msh->fds);
|
||||
signal(SIGINT, signal_handler_interactive);
|
||||
signal(SIGQUIT, signal_handler_interactive);
|
||||
//set_echoctl(0);
|
||||
}
|
||||
|
||||
void exec_commands(t_msh *msh)
|
||||
@ -136,9 +136,7 @@ void exec_commands(t_msh *msh)
|
||||
ft_exit(msh, 1);
|
||||
i = -1;
|
||||
while (++i < cmd_count && msh->in_fd >= 0 && msh->out_fd >= 0)
|
||||
{
|
||||
get_redirections(msh, msh->cmds);
|
||||
exec_command(msh, i, cmd_count);
|
||||
}
|
||||
free_token(msh->tokens);
|
||||
end_execution(msh, cmd_count);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/24 17:44:32 by marde-vr #+# #+# */
|
||||
/* Updated: 2024/04/25 18:38:34 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/04/26 11:06:25 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -39,7 +39,9 @@ void here_doc_child(t_msh *msh, char *eof)
|
||||
{
|
||||
rl_catch_signals = 1;
|
||||
here_doc_variables(1, msh);
|
||||
set_echoctl(0);
|
||||
signal(SIGINT, signal_handler_here_doc);
|
||||
signal(SIGQUIT, SIG_IGN);
|
||||
get_here_doc_input(msh, eof);
|
||||
close(msh->in_fd);
|
||||
ft_exit(msh, 0);
|
||||
@ -52,6 +54,7 @@ void here_doc_signal(t_msh *msh, int child_pid, char *here_doc_file)
|
||||
signal(SIGINT, signal_handler_command);
|
||||
signal(SIGQUIT, signal_handler_here_doc);
|
||||
waitpid(child_pid, &status, 0);
|
||||
set_echoctl(msh->echoctl);
|
||||
signal(SIGINT, signal_handler_interactive);
|
||||
signal(SIGQUIT, signal_handler_interactive);
|
||||
close(msh->in_fd);
|
||||
|
11
srcs/main.c
11
srcs/main.c
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
|
||||
/* Updated: 2024/04/26 10:24:46 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/04/26 11:02:41 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -82,7 +82,7 @@ t_env *add_shlvl(t_env *env)
|
||||
else
|
||||
nb = ft_atoi(tmp);
|
||||
nb++;
|
||||
if(nb < 0)
|
||||
if (nb < 0)
|
||||
nb = 0;
|
||||
env = export_set_env(env, ft_strdup("SHLVL"), ft_itoa(nb), 0);
|
||||
return (env);
|
||||
@ -90,11 +90,18 @@ t_env *add_shlvl(t_env *env)
|
||||
|
||||
int init_minishell(t_msh **msh, int argc, char **argv, char **envp)
|
||||
{
|
||||
struct termios t_p;
|
||||
|
||||
*msh = ft_calloc(1, sizeof(t_msh));
|
||||
if (!*msh)
|
||||
exit(1);
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
if (isatty(1))
|
||||
{
|
||||
tcgetattr(1, &t_p);
|
||||
(*msh)->echoctl = t_p.c_lflag & ECHOCTL;
|
||||
}
|
||||
(*msh)->env = get_env(envp);
|
||||
(*msh)->env = add_shlvl((*msh)->env);
|
||||
rl_catch_signals = 0;
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */
|
||||
/* Updated: 2024/04/25 18:39:18 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/04/26 11:06:01 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -43,7 +43,7 @@ void signal_handler_here_doc(int signum)
|
||||
{
|
||||
msh = here_doc_variables(0, 0);
|
||||
rl_on_new_line();
|
||||
printf("\n");
|
||||
printf("^C\n");
|
||||
if(msh->in_fd > 2)
|
||||
close(msh->in_fd);
|
||||
ft_exit(msh, 1);
|
||||
@ -52,9 +52,6 @@ void signal_handler_here_doc(int signum)
|
||||
|
||||
int set_echoctl(int value)
|
||||
{
|
||||
printf("nope");
|
||||
(void)value;
|
||||
/*
|
||||
struct termios t_p;
|
||||
|
||||
if (!isatty(1))
|
||||
@ -70,8 +67,6 @@ int set_echoctl(int value)
|
||||
if (tcsetattr(1, TCSANOW, &t_p))
|
||||
return (1);
|
||||
return (0);
|
||||
*/
|
||||
return(0);
|
||||
}
|
||||
|
||||
void signal_handler_command(int signum)
|
||||
|
Reference in New Issue
Block a user