here doc sigint

This commit is contained in:
2024-03-25 19:15:34 +01:00
parent 6ffeebf87b
commit 50dd393b36
4 changed files with 48 additions and 10 deletions

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/25 18:12:26 by tomoron ### ########.fr */
/* Updated: 2024/03/25 19:14:46 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -84,6 +84,8 @@ void get_here_doc_input(t_msh *msh, char *eof)
char *line;
line = NULL;
signal(SIGINT, signal_handler_here_doc);
signal(SIGQUIT, signal_handler_here_doc);
while (1)
{
free(line);
@ -106,6 +108,7 @@ void handle_here_doc(t_msh *msh, char *eof)
{
char *here_doc_file;
int pid;
int status;
here_doc_file = get_tmp_file_name(msh);
msh->in_fd = open(here_doc_file, O_CREAT | O_RDWR, 0644);
@ -117,6 +120,8 @@ void handle_here_doc(t_msh *msh, char *eof)
pid = fork();
if (pid == 0)
{
here_doc_variables(1, 0, msh);
here_doc_variables(1, 1, here_doc_file);
get_here_doc_input(msh, eof);
close(msh->in_fd);
free(here_doc_file);
@ -125,14 +130,17 @@ void handle_here_doc(t_msh *msh, char *eof)
}
else
{
waitpid(pid, 0 , 0);
signal(SIGINT, signal_handler_command);
signal(SIGQUIT, signal_handler_command);
waitpid(pid, &status , 0);
signal(SIGINT, signal_handler_interactive);
signal(SIGQUIT, signal_handler_interactive);
close(msh->in_fd);
if(WIFEXITED(status) && WEXITSTATUS(status))
unlink(here_doc_file);
msh->in_fd = open(here_doc_file, O_RDWR, 0644);
free(here_doc_file);
if (msh->in_fd == -1)
{
if (msh->in_fd == -1 && !(WIFEXITED(status) && WEXITSTATUS(status)))
perror("open");
ft_exit(msh, 1);
}
}
}