here doc sigint
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */
|
||||
/* Updated: 2024/03/25 13:49:08 by marde-vr ### ########.fr */
|
||||
/* Updated: 2024/03/25 19:01:25 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -89,7 +89,7 @@ void exec_commands(t_msh *msh)
|
||||
waitpid(msh->pids[i], &status, 0);
|
||||
i++;
|
||||
}
|
||||
if(!g_return_code)
|
||||
if(!g_return_code && WIFEXITED(status))
|
||||
g_return_code = WEXITSTATUS(status);
|
||||
i = 0;
|
||||
while (i < 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/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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
|
||||
/* Updated: 2024/03/25 18:15:41 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/03/25 18:42:00 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -109,6 +109,8 @@ int file_access(t_msh *msh, int *found);
|
||||
char *remove_path(char *token);
|
||||
void signal_handler_interactive(int signum);
|
||||
void signal_handler_command(int signum);
|
||||
void signal_handler_here_doc(int signum);
|
||||
char *get_var_name(char *str);
|
||||
void *here_doc_variables(int write, int index, void *data);
|
||||
|
||||
#endif
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */
|
||||
/* Updated: 2024/03/23 19:21:24 by marde-vr ### ########.fr */
|
||||
/* Updated: 2024/03/25 19:10:39 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -29,6 +29,34 @@ void signal_handler_interactive(int signum)
|
||||
}
|
||||
}
|
||||
|
||||
void *here_doc_variables(int write, int index, void *data)
|
||||
{
|
||||
static void *variables[2];
|
||||
|
||||
if (write)
|
||||
variables[index] = data;
|
||||
else
|
||||
return (variables[index]);
|
||||
return(0);
|
||||
}
|
||||
|
||||
void signal_handler_here_doc(int signum)
|
||||
{
|
||||
t_msh *msh;
|
||||
char *here_doc_file;
|
||||
|
||||
if(signum == 2)
|
||||
{
|
||||
write(1,"\n",1);
|
||||
msh = here_doc_variables(0, 0, 0);
|
||||
here_doc_file = here_doc_variables(0, 1, 0);
|
||||
close(msh->in_fd);
|
||||
free(here_doc_file);
|
||||
free(msh->fds[0]);
|
||||
ft_exit(msh, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void signal_handler_command(int signum)
|
||||
{
|
||||
(void)signum;
|
||||
|
Reference in New Issue
Block a user