des trucs
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/23 16:32:16 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/04/23 17:01:43 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -186,6 +186,12 @@ void end_execution(t_msh *msh, int cmd_count)
|
||||
g_return_code = WEXITSTATUS(status);
|
||||
if (WIFSIGNALED(status))
|
||||
print_signaled(status);
|
||||
if(msh->here_doc_filename)
|
||||
{
|
||||
unlink(msh->here_doc_filename)
|
||||
free(msh->here_doc_filename);
|
||||
msh->here_doc_filename = 0;
|
||||
{
|
||||
free(msh->pids);
|
||||
free_fds(msh);
|
||||
msh->pids = 0;
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/24 17:44:32 by marde-vr #+# #+# */
|
||||
/* Updated: 2024/04/23 16:41:42 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/04/23 16:59:17 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -38,13 +38,10 @@ void get_here_doc_input(t_msh *msh, char *eof)
|
||||
|
||||
void here_doc_child(t_msh *msh, char *eof, char *here_doc_file)
|
||||
{
|
||||
here_doc_variables(1, 0, msh);
|
||||
here_doc_variables(1, 1, here_doc_file);
|
||||
here_doc_variables(1, msh);
|
||||
signal(SIGINT, signal_handler_here_doc);
|
||||
get_here_doc_input(msh, eof);
|
||||
close(msh->in_fd);
|
||||
printf("close2");
|
||||
free(here_doc_file);
|
||||
ft_exit(msh, 0);
|
||||
}
|
||||
|
||||
@ -58,11 +55,9 @@ void here_doc_signal(t_msh *msh, int child_pid, char *here_doc_file)
|
||||
signal(SIGINT, signal_handler_interactive);
|
||||
signal(SIGQUIT, signal_handler_interactive);
|
||||
close(msh->in_fd);
|
||||
printf("close 1\n");
|
||||
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 && !(WIFEXITED(status) && WEXITSTATUS(status)))
|
||||
perror("open");
|
||||
}
|
||||
@ -73,6 +68,7 @@ void handle_here_doc(t_msh *msh, char *eof)
|
||||
int pid;
|
||||
|
||||
here_doc_file = get_tmp_file_name(msh);
|
||||
msh->here_doc_filename = here_doc_file;
|
||||
msh->in_fd = open(here_doc_file, O_CREAT | O_RDWR, 0644);
|
||||
if (msh->in_fd == -1)
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
|
||||
/* Updated: 2024/04/23 16:31:56 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/04/23 16:52:15 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -73,6 +73,7 @@ typedef struct s_msh
|
||||
int out_fd;
|
||||
int locked_return_code;
|
||||
int echoctl;
|
||||
char *here_doc_filename;
|
||||
} t_msh;
|
||||
|
||||
extern int g_return_code;
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */
|
||||
/* Updated: 2024/04/22 19:53:34 by marde-vr ### ########.fr */
|
||||
/* Updated: 2024/04/23 16:59:02 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -26,29 +26,26 @@ void signal_handler_interactive(int signum)
|
||||
printf("%s%s", rl_prompt, rl_line_buffer);
|
||||
}
|
||||
|
||||
void *here_doc_variables(int write, int index, void *data)
|
||||
void *here_doc_variables(int write, void *data)
|
||||
{
|
||||
static void *variables[2];
|
||||
static void *variable;
|
||||
|
||||
if (write)
|
||||
variables[index] = data;
|
||||
variables = data;
|
||||
else
|
||||
return (variables[index]);
|
||||
return (variables);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void signal_handler_here_doc(int signum)
|
||||
{
|
||||
t_msh *msh;
|
||||
char *here_doc_file;
|
||||
|
||||
if (signum == SIGINT)
|
||||
{
|
||||
printf("%s%s^C\n", rl_prompt, rl_line_buffer);
|
||||
msh = here_doc_variables(0, 0, 0);
|
||||
here_doc_file = here_doc_variables(0, 1, 0);
|
||||
msh = here_doc_variables(0, 0);
|
||||
close(msh->in_fd);
|
||||
free(here_doc_file);
|
||||
ft_exit(msh, 1);
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/05 18:19:26 by marde-vr #+# #+# */
|
||||
/* Updated: 2024/04/23 16:41:42 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/04/23 16:58:07 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -38,6 +38,7 @@ void free_msh(t_msh *msh)
|
||||
free(msh->pids);
|
||||
free_cmd(msh->cmds_head);
|
||||
free_fds(msh);
|
||||
free(msh->here_doc_filename);
|
||||
free_token(msh->tokens);
|
||||
free(msh);
|
||||
}
|
||||
|
Reference in New Issue
Block a user