Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added libft/ft_printf/libftprintf.a
Binary file not shown.
Binary file added libft/libft.a
Binary file not shown.
Binary file added minishell
Binary file not shown.
12 changes: 9 additions & 3 deletions src/executor/handle_multiple_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: cter-maa <cter-maa@student.codam.nl> +#+ */
/* +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down
37 changes: 19 additions & 18 deletions src/executor/heredoc.c
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* heredoc.c :+: :+: */
/* +:+ */
/* By: cter-maa <cter-maa@student.codam.nl> +#+ */
/* +#+ */
/* 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))
Expand All @@ -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)
Expand All @@ -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];
}
}