des trucs

This commit is contained in:
2024-04-23 17:03:30 +02:00
parent 905bbc659b
commit 2d8624d221
5 changed files with 20 additions and 19 deletions

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */ /* 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); g_return_code = WEXITSTATUS(status);
if (WIFSIGNALED(status)) if (WIFSIGNALED(status))
print_signaled(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(msh->pids);
free_fds(msh); free_fds(msh);
msh->pids = 0; msh->pids = 0;

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/24 17:44:32 by marde-vr #+# #+# */ /* 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) void here_doc_child(t_msh *msh, char *eof, char *here_doc_file)
{ {
here_doc_variables(1, 0, msh); here_doc_variables(1, msh);
here_doc_variables(1, 1, here_doc_file);
signal(SIGINT, signal_handler_here_doc); signal(SIGINT, signal_handler_here_doc);
get_here_doc_input(msh, eof); get_here_doc_input(msh, eof);
close(msh->in_fd); close(msh->in_fd);
printf("close2");
free(here_doc_file);
ft_exit(msh, 0); 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(SIGINT, signal_handler_interactive);
signal(SIGQUIT, signal_handler_interactive); signal(SIGQUIT, signal_handler_interactive);
close(msh->in_fd); close(msh->in_fd);
printf("close 1\n");
if (WIFEXITED(status) && WEXITSTATUS(status)) if (WIFEXITED(status) && WEXITSTATUS(status))
unlink(here_doc_file); unlink(here_doc_file);
msh->in_fd = open(here_doc_file, O_RDWR, 0644); msh->in_fd = open(here_doc_file, O_RDWR, 0644);
free(here_doc_file);
if (msh->in_fd == -1 && !(WIFEXITED(status) && WEXITSTATUS(status))) if (msh->in_fd == -1 && !(WIFEXITED(status) && WEXITSTATUS(status)))
perror("open"); perror("open");
} }
@ -73,6 +68,7 @@ void handle_here_doc(t_msh *msh, char *eof)
int pid; int pid;
here_doc_file = get_tmp_file_name(msh); 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); msh->in_fd = open(here_doc_file, O_CREAT | O_RDWR, 0644);
if (msh->in_fd == -1) if (msh->in_fd == -1)
{ {

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */ /* 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 out_fd;
int locked_return_code; int locked_return_code;
int echoctl; int echoctl;
char *here_doc_filename;
} t_msh; } t_msh;
extern int g_return_code; extern int g_return_code;

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */ /* 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); 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) if (write)
variables[index] = data; variables = data;
else else
return (variables[index]); return (variables);
return (0); return (0);
} }
void signal_handler_here_doc(int signum) void signal_handler_here_doc(int signum)
{ {
t_msh *msh; t_msh *msh;
char *here_doc_file;
if (signum == SIGINT) if (signum == SIGINT)
{ {
printf("%s%s^C\n", rl_prompt, rl_line_buffer); printf("%s%s^C\n", rl_prompt, rl_line_buffer);
msh = here_doc_variables(0, 0, 0); msh = here_doc_variables(0, 0);
here_doc_file = here_doc_variables(0, 1, 0);
close(msh->in_fd); close(msh->in_fd);
free(here_doc_file);
ft_exit(msh, 1); ft_exit(msh, 1);
} }
} }

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:19:26 by marde-vr #+# #+# */ /* 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(msh->pids);
free_cmd(msh->cmds_head); free_cmd(msh->cmds_head);
free_fds(msh); free_fds(msh);
free(msh->here_doc_filename);
free_token(msh->tokens); free_token(msh->tokens);
free(msh); free(msh);
} }