From 404fcaa15f26ad6102f083a7067ecacdfad54c0e Mon Sep 17 00:00:00 2001 From: Camille Chauvet Date: Wed, 5 Apr 2023 14:13:56 +0200 Subject: [PATCH] fix: heredoc signal --- redirection/check.c | 19 +++++++++++++++---- redirection/heredoc.c | 17 +++++++++++++---- redirection/redirection.c | 5 +++-- signal/signal.c | 5 +++-- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/redirection/check.c b/redirection/check.c index 543cd87..e97db5b 100644 --- a/redirection/check.c +++ b/redirection/check.c @@ -6,7 +6,7 @@ /* By: cchauvet fd_in[0] == -2) + return (0); fd = ft_heredoc(data, redirection); if (fd == -2) return (1); @@ -39,6 +41,8 @@ static bool ft_check_infile(t_data *data, t_cmd *cmd, if (ft_strcmp(redirection_identifier, "<") == 0) { + if (cmd->fd_in[0] == -2) + return (0); if (ft_file_is_readable(data, redirection)) { fd = open(redirection, O_RDONLY); @@ -51,7 +55,7 @@ static bool ft_check_infile(t_data *data, t_cmd *cmd, if (cmd->fd_in[0] > 2) close(cmd->fd_in[0]); cmd->fd_in[0] = -2; - return (1); + return (0); } } return (0); @@ -64,6 +68,8 @@ static bool ft_check_outfile(t_data *data, t_cmd *cmd, if (ft_strcmp(redirection_identifier, ">") == 0) { + if (cmd->fd_out[0] == -2) + return (0); if (ft_file_is_writable(data, redirection)) { fd = open(redirection, @@ -77,7 +83,7 @@ static bool ft_check_outfile(t_data *data, t_cmd *cmd, if (cmd->fd_out[0] > 2) close(cmd->fd_out[0]); cmd->fd_out[0] = -2; - return (1); + return (0); } } return (0); @@ -90,6 +96,8 @@ static bool ft_check_outfile_append(t_data *data, t_cmd *cmd, if (ft_strcmp(redirection_identifier, ">>") == 0) { + if (cmd->fd_out[0] == -2) + return (0); if (ft_file_is_writable(data, redirection)) { fd = open(redirection, @@ -103,7 +111,6 @@ static bool ft_check_outfile_append(t_data *data, t_cmd *cmd, if (cmd->fd_out[0] > 2) close(cmd->fd_out[0]); cmd->fd_out[0] = -2; - return (1); } } return (0); @@ -131,6 +138,10 @@ bool ft_check_redirection(t_data *data, t_cmd *cmd, || ft_check_outfile(data, cmd, redirection_identifier, str) || ft_check_outfile_append(data, cmd, redirection_identifier, str)) + { + free(str); + return (1); + } ; free(str); return (0); diff --git a/redirection/heredoc.c b/redirection/heredoc.c index 8d451d7..cb0ca04 100644 --- a/redirection/heredoc.c +++ b/redirection/heredoc.c @@ -6,7 +6,7 @@ /* By: cchauvet ", tab[i][0])) diff --git a/signal/signal.c b/signal/signal.c index 82ac1d1..2e166ca 100644 --- a/signal/signal.c +++ b/signal/signal.c @@ -6,7 +6,7 @@ /* By: cchauvet exit_code = 130; if (*ft_get_heredoc() != -1) { - close(*ft_get_heredoc()); + if (*ft_get_heredoc() > 2) + close(*ft_get_heredoc()); *ft_get_heredoc() = -1; } else