diff --git a/libft/ft_printf/libftprintf.a b/libft/ft_printf/libftprintf.a new file mode 100644 index 0000000..79ae65f Binary files /dev/null and b/libft/ft_printf/libftprintf.a differ diff --git a/libft/libft.a b/libft/libft.a new file mode 100644 index 0000000..208bfb2 Binary files /dev/null and b/libft/libft.a differ diff --git a/minishell b/minishell new file mode 100755 index 0000000..08ca90e Binary files /dev/null and b/minishell differ diff --git a/src/executor/handle_multiple_commands.c b/src/executor/handle_multiple_commands.c index 8461953..6051033 100644 --- a/src/executor/handle_multiple_commands.c +++ b/src/executor/handle_multiple_commands.c @@ -6,7 +6,7 @@ /* By: cter-maa +#+ */ /* +#+ */ /* Created: 2023/08/23 16:37:28 by cter-maa #+# #+# */ -/* Updated: 2023/08/24 13:35:27 by fhuisman ######## odam.nl */ +/* Updated: 2023/08/24 15:53:45 by cter-maa ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -48,7 +48,10 @@ static int execute_last_command(t_shell *shell, t_command *command, perror_exit_fork(shell, "dup2"); handle_redirection(shell, command, pid); if (check_if_builtin(command->args[0])) + { execute_builtin(shell, command); + _exit(0); + } else execute_non_builtin(shell, command); } @@ -62,18 +65,21 @@ static void execute_childs(t_shell *shell, t_command *command, { if (dup2(read_end, STDIN_FILENO) == FAILED) perror_exit_fork(shell, "dup2"); + handle_redirection(shell, command, 0); if (dup2(pipe_fd[WRITE_END], STDOUT_FILENO) == FAILED) perror_exit_fork(shell, "dup2"); - handle_redirection(shell, command, 0); if (check_if_builtin(command->args[0]) == TRUE) + { execute_builtin(shell, command); + _exit(0); + } else execute_non_builtin(shell, command); if (close(pipe_fd[WRITE_END]) == FAILED) perror_exit_fork(shell, "close"); } -static int_fast16_t create_forks(t_shell *shell, t_command *command, int read_end, +static int create_forks(t_shell *shell, t_command *command, int read_end, int *fd) { pid_t pid; diff --git a/src/executor/heredoc.c b/src/executor/heredoc.c index 734a865..e7dd919 100644 --- a/src/executor/heredoc.c +++ b/src/executor/heredoc.c @@ -1,32 +1,32 @@ -/* ************************************************************************** */ -/* */ -/* :::::::: */ -/* heredoc.c :+: :+: */ -/* +:+ */ -/* By: cter-maa +#+ */ -/* +#+ */ -/* Created: 2023/08/23 16:49:47 by cter-maa #+# #+# */ -/* Updated: 2023/08/24 11:35:51 by fhuisman ######## odam.nl */ -/* */ -/* ************************************************************************** */ - #include "../../include/minishell.h" static void here_wait(t_shell *shell, pid_t pid, int status) { if (waitpid(pid, &status, 0) == FAILED) - return (perror_update_status(shell, "waitpid")); + perror_exit_fork(shell, "waitpid"); if (WIFSIGNALED(status)) shell->status = g_status; else shell->status = WEXITSTATUS(status); } +static void sigint_handler_heredoc(int signum) +{ + (void) signum; + _exit(1); +} + +static void init_signals_heredoc(void) +{ + signal(SIGINT, &sigint_handler_heredoc); + signal(SIGTSTP, SIG_IGN); + signal(SIGQUIT, SIG_IGN); +} + static void write_to_pipe(t_shell *shell, char *delimiter, int pipe_fd) { char *line; - init_signals(HEREDOC); line = readline("> "); while (line && !(ft_strncmp(line, delimiter, ft_strlen(delimiter) + 1) == 0)) @@ -50,6 +50,8 @@ void create_heredoc(t_shell *shell, t_redir *redir) pid_t pid; status = 0; + if (redir->heredoc_read_end) + close(redir->heredoc_read_end); if (!redir->file || redir->file[0] == '\0') return (perror_update_status(shell, "close")); if (pipe(pipe_fd) == FAILED) @@ -59,12 +61,11 @@ void create_heredoc(t_shell *shell, t_redir *redir) return (perror_update_status(shell, "fork")); if (pid == SUCCESS) { - if (close(pipe_fd[READ_END] == FAILED)) - return (perror_update_status(shell, "close")); + init_signals_heredoc(); write_to_pipe(shell, redir->file, pipe_fd[WRITE_END]); } - else if (close(pipe_fd[WRITE_END]) == FAILED) + if (close(pipe_fd[WRITE_END]) == FAILED) perror_exit_fork(shell, "close"); here_wait(shell, pid, status); redir->heredoc_read_end = pipe_fd[READ_END]; -} +} \ No newline at end of file