gestion des signaux avec execve ok dans test
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/10/04 05:59:26 by lperrey #+# #+# */
|
||||
/* Updated: 2021/11/11 09:54:40 by hulamy ### ########.fr */
|
||||
/* Updated: 2021/11/15 20:21:59 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -57,12 +57,20 @@ void execute_cmd(char **envp, t_cmd **cmd_arr, t_all *c)
|
||||
int i;
|
||||
int argc;
|
||||
|
||||
// put signal handling for SIGINT to ignore so parent process will not activate signal_handling_executiv while childs are in process
|
||||
// c->signal_behaviour.sa_handler = SIG_IGN;
|
||||
// sigaction(SIGINT, &c->signal_behaviour, NULL);
|
||||
signal(SIGINT, SIG_IGN);
|
||||
i = 0;
|
||||
while(cmd_arr[i])
|
||||
{
|
||||
pid = fork();
|
||||
if (pid == 0)
|
||||
{
|
||||
// activate singal handling for execution mode
|
||||
// c->signal_behaviour.sa_handler = sigint_handler_execution;
|
||||
// sigaction(SIGINT, &c->signal_behaviour, NULL);
|
||||
signal(SIGINT, sigint_handler_execution);
|
||||
if (cmd_arr[i]->fd_in != 0)
|
||||
dup2(cmd_arr[i]->fd_in, STDIN_FILENO);
|
||||
if (cmd_arr[i]->fd_out != 1)
|
||||
@@ -74,9 +82,13 @@ void execute_cmd(char **envp, t_cmd **cmd_arr, t_all *c)
|
||||
while (cmd_arr[i]->argv[argc])
|
||||
argc++;
|
||||
cmd_arr[i]->builtin_command(argc, cmd_arr[i]->argv, c);
|
||||
exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
write(1, "1", 1);
|
||||
execve(cmd_arr[i]->argv[0], cmd_arr[i]->argv, envp);
|
||||
}
|
||||
}
|
||||
else
|
||||
close_fd(cmd_arr[i]);
|
||||
@@ -84,4 +96,7 @@ void execute_cmd(char **envp, t_cmd **cmd_arr, t_all *c)
|
||||
}
|
||||
// waitpid pour la derniere commande (pour '$?')
|
||||
while ((wpid = wait(&status)) > 0);
|
||||
// put signal handling for sigint back to the signal handler for interactiv mode
|
||||
c->signal_behaviour.sa_handler = sigint_handler_interactiv;
|
||||
sigaction(SIGINT, &c->signal_behaviour, NULL);
|
||||
}
|
||||
|
||||
@@ -6,25 +6,31 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/10/23 18:56:53 by lperrey #+# #+# */
|
||||
/* Updated: 2021/11/10 13:44:09 by hulamy ### ########.fr */
|
||||
/* Updated: 2021/11/15 20:08:26 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
void sigint_handler(int signum)
|
||||
void sigint_handler_interactiv(int signum)
|
||||
{
|
||||
(void)signum;
|
||||
write(1, "\n", 1);
|
||||
rl_replace_line("", 1);
|
||||
rl_on_new_line();
|
||||
rl_redisplay();
|
||||
return ;
|
||||
}
|
||||
|
||||
void sigint_handler_execution(int signum)
|
||||
{
|
||||
(void)signum;
|
||||
write(1, "\n", 1);
|
||||
// exit(0);
|
||||
}
|
||||
|
||||
int set_signals_handling(struct sigaction *signal_behaviour)
|
||||
{
|
||||
signal_behaviour->sa_handler = sigint_handler;
|
||||
signal_behaviour->sa_handler = sigint_handler_interactiv;
|
||||
sigaction(SIGINT, signal_behaviour, NULL);
|
||||
signal_behaviour->sa_handler = SIG_IGN;
|
||||
sigaction(SIGQUIT, signal_behaviour, NULL);
|
||||
|
||||
Reference in New Issue
Block a user