gestion des signaux avec execve ok dans test

This commit is contained in:
hugogogo
2021-11-15 21:56:50 +01:00
parent 57c271b9e2
commit 36766501ba
5 changed files with 51 additions and 8 deletions

View File

@@ -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);
}