signal in heredoc

This commit is contained in:
whaffman 2025-03-07 17:46:35 +01:00
parent c9c579c9bb
commit ace00a615b
5 changed files with 41 additions and 14 deletions

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/23 12:26:29 by Quinten #+# #+# */
/* Updated: 2025/02/28 14:08:33 by whaffman ######## odam.nl */
/* Updated: 2025/03/07 17:25:54 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -24,5 +24,6 @@ int redirect_is_valid(t_list *lst, t_token *token, int mode);
int redirect_token_type(t_token *token);
int redirect_is_delimiter(t_token *token);
int process_heredoc(t_minishell *msh, t_token *heredoc, t_token *delim);
int fork_for_heredoc(t_minishell *msh,
t_token *heredoc, t_token *delim);
#endif

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/19 12:26:09 by whaffman #+# #+# */
/* Updated: 2025/02/19 17:30:12 by whaffman ######## odam.nl */
/* Updated: 2025/03/07 17:26:57 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -21,5 +21,6 @@ void sig_parent_handler(int signum);
void signal_init_child(void);
void signal_init_parent(void);
void signal_init_minishell(void);
void signal_init_heredoc(void);
#endif // SIGNALS_H

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/23 12:29:05 by Quinten #+# #+# */
/* Updated: 2025/02/28 14:00:39 by whaffman ######## odam.nl */
/* Updated: 2025/03/07 17:41:51 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -15,7 +15,8 @@
static void check_heredoc(t_minishell *msh, t_list *current, t_token *token)
{
if (token->type == T_HEREDOC && redirect_is_valid(current, token, -1))
process_heredoc(msh, token, current->next->content);
fork_for_heredoc(msh, token, current->next->content);
}
t_list *redirect_get_inputs(t_minishell *msh, t_list *list)

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* redirect_process_heredoc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/26 16:46:32 by qmennen #+# #+# */
/* Updated: 2025/02/26 16:54:09 by qmennen ### ########.fr */
/* :::::::: */
/* redirect_process_heredoc.c :+: :+: */
/* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/26 16:46:32 by qmennen #+# #+# */
/* Updated: 2025/03/07 17:44:38 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -26,6 +26,31 @@
*
* Return: 1 on success, or a negative value on failure.
*/
int fork_for_heredoc(t_minishell *msh, t_token *heredoc, t_token *delim)
{
int pid;
int status;
pid = fork();
if (pid < 0)
{
error_msg("heredoc", "fork failed");
return (pid);
}
if (pid == 0)
{
signal_init_heredoc();
process_heredoc(msh, heredoc, delim);
exit(0);
}
signal_init_minishell();
waitpid(pid, &status, 0);
heredoc->type = T_REDIRECT_IN;
delim->value = ft_strdup_safe(msh, ".ms_heredoc");
return (0);
}
int process_heredoc(t_minishell *msh, t_token *heredoc, t_token *delim)
{
char *line;

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/19 12:18:47 by whaffman #+# #+# */
/* Updated: 2025/02/26 15:42:30 by whaffman ######## odam.nl */
/* Updated: 2025/03/07 17:34:59 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -24,7 +24,6 @@ void sigint_minishell_handler(int signum)
void sigint_heredoc_handler(int signum)
{
(void)signum;
ft_putstr_fd("\n", 1);
rl_on_new_line();
rl_replace_line("", 0);
exit(130);