dont throw away of_fd before testing the new one

This commit is contained in:
whaffman 2025-02-21 13:17:22 +01:00
parent 3631e127e4
commit 8c02b32601
6 changed files with 26 additions and 24 deletions

View File

@ -6,7 +6,7 @@
/* By: willem <willem@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/08 17:06:07 by willem #+# #+# */
/* Updated: 2025/02/21 13:01:39 by whaffman ######## odam.nl */
/* Updated: 2025/02/21 13:16:29 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -22,7 +22,7 @@ void executor_create_pipes(t_minishell *minishell);
int executor_execute_pipeline(t_minishell *minishell);
void executor_close_fds(int n_fds);
int executor_count_fds(t_minishell *minishell);
int executor_open_fds(t_list *redirect_list);
int executor_open_fds(t_list *redirect_list, int og_fd);
void executor_create_redirects(t_minishell *minishell);
#endif // EXECUTOR_H

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/21 12:42:26 by whaffman #+# #+# */
/* Updated: 2025/02/21 12:46:00 by whaffman ######## odam.nl */
/* Updated: 2025/02/21 13:05:55 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -14,12 +14,10 @@
int executor_count_fds(t_minishell *minishell)
{
int fd;
int count;
t_list *current;
t_command *command;
current = minishell->commands;
count = (ft_lstsize(current) - 1) * 2;
while (current)

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/21 13:00:00 by whaffman #+# #+# */
/* Updated: 2025/02/21 13:00:11 by whaffman ######## odam.nl */
/* Updated: 2025/02/21 13:16:03 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -15,14 +15,14 @@
void executor_create_redirects(t_minishell *minishell)
{
t_list *current;
t_command *command;
t_command *cmd;
current = minishell->commands;
while (current)
{
command = (t_command *)current->content;
command->fd_in = executor_open_fds(command->redirect_in);
command->fd_out = executor_open_fds(command->redirect_out);
cmd = (t_command *)current->content;
cmd->fd_in = executor_open_fds(cmd->redirect_in, cmd->fd_in);
cmd->fd_out = executor_open_fds(cmd->redirect_out, cmd->fd_out);
current = current->next;
}
}

View File

@ -6,7 +6,7 @@
/* By: willem <willem@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/12 21:25:02 by willem #+# #+# */
/* Updated: 2025/02/21 12:49:21 by whaffman ######## odam.nl */
/* Updated: 2025/02/21 13:11:17 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */

View File

@ -6,18 +6,18 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/21 12:50:42 by whaffman #+# #+# */
/* Updated: 2025/02/21 12:59:41 by whaffman ######## odam.nl */
/* Updated: 2025/02/21 13:15:04 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "minishell.h"
int executor_open_fds(t_list *redirect_list)
int executor_open_fds(t_list *redirect_list, int og_fd)
{
t_redirect *redirect;
int fd;
fd = 0;
fd = og_fd;
while (redirect_list)
{
redirect = (t_redirect *)redirect_list->content;
@ -30,7 +30,7 @@ int executor_open_fds(t_list *redirect_list)
if (fd < 0)
{
error_msg("executor_open_fds", "can't open file");
return (fd);
return (og_fd);
}
redirect_list = redirect_list->next;
}

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parser_new_command.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* :::::::: */
/* parser_new_command.c :+: :+: */
/* +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/02/11 16:18:21 by qmennen #+# #+# */
/* Updated: 2025/02/11 16:25:12 by qmennen ### ########.fr */
/* Updated: 2025/02/21 13:07:47 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -25,6 +25,10 @@ t_command *parser_command_new(char *cmd)
command->args = NULL;
command->fd_in = 0;
command->fd_out = 1;
command->redirect_in = NULL;
command->redirect_out = NULL;
command->environment = NULL;
command->n_fds = 0;
command->command = cmd;
return (command);
}