mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 03:16:51 +01:00
「🔨」 fix(exec): fixed open FD when redirection with pipe
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/29 13:20:22 by mmoussou #+# #+# */
|
||||
/* Updated: 2024/07/18 14:34:25 by mmoussou ### ########.fr */
|
||||
/* Updated: 2024/08/01 16:39:11 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -37,9 +37,10 @@ int is_in_builtins(char *cmd);
|
||||
char *get_cmd_local_path(char *cmd, t_env *env);
|
||||
void print_return_value(int return_code);
|
||||
void __wait(int i);
|
||||
void __close(void *content);
|
||||
void __close(void *content, int fd1, int fd2);
|
||||
int check_file(char *cmd, char *input);
|
||||
void free_exec(t_env *env, char **env_array);
|
||||
void ft_arrcpy(int *dst, int *src, int n);
|
||||
|
||||
void exec_cmd(t_cmd *cmd, char **env, t_env *env_t);
|
||||
void __fork_single_cmd(t_cmd *cmd, char **env, t_env *env_t, t_exec exec);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/01 14:55:06 by mmoussou #+# #+# */
|
||||
/* Updated: 2024/08/01 06:10:04 by mmoussou ### ########.fr */
|
||||
/* Updated: 2024/08/01 16:38:31 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -26,9 +26,8 @@ int exec_fork_cmd(t_cmd *cmd, char **env, t_env *env_t, int pipe_fd[2])
|
||||
|
||||
if (!cmd->cmd)
|
||||
return (get_exit_code(0));
|
||||
ft_arrcpy(exec.pipe_fd, pipe_fd, 2);
|
||||
input = ft_strdup(cmd->cmd);
|
||||
exec.pipe_fd[0] = pipe_fd[0];
|
||||
exec.pipe_fd[1] = pipe_fd[1];
|
||||
exec.status = switch_cmd_path(cmd, env_t);
|
||||
if (exec.status == -1 || !input || check_file(cmd->cmd, input))
|
||||
{
|
||||
@ -106,7 +105,7 @@ t_exec exec_pipe(t_exec exec, t_list *list_cmd, t_env *env)
|
||||
((t_cmd *)(list_cmd->next->content))->infile = exec.pipe_fd[0];
|
||||
exec.status = exec_fork_cmd(list_cmd->content, exec.env_array, \
|
||||
env, exec.pipe_fd);
|
||||
__close(list_cmd->content);
|
||||
__close(list_cmd->content, exec.pipe_fd[0], exec.pipe_fd[1]);
|
||||
if (exec.status != -1)
|
||||
exec.i++;
|
||||
list_cmd = list_cmd->next;
|
||||
@ -114,7 +113,7 @@ t_exec exec_pipe(t_exec exec, t_list *list_cmd, t_env *env)
|
||||
exec.status = exec_fork_cmd(list_cmd->content, exec.env_array, \
|
||||
env, exec.pipe_fd);
|
||||
__sig2(exec.status);
|
||||
__close(list_cmd->content);
|
||||
__close(list_cmd->content, exec.pipe_fd[0], exec.pipe_fd[1]);
|
||||
return (exec);
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/09 22:53:01 by adjoly #+# #+# */
|
||||
/* Updated: 2024/07/16 15:49:01 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/08/01 16:38:54 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -22,12 +22,16 @@ void __wait(int i)
|
||||
}
|
||||
}
|
||||
|
||||
void __close(void *content)
|
||||
void __close(void *content, int fd1, int fd2)
|
||||
{
|
||||
if (((t_cmd *)(content))->outfile != STDOUT_FILENO)
|
||||
close(((t_cmd *)(content))->outfile);
|
||||
if (((t_cmd *)(content))->infile != STDIN_FILENO)
|
||||
close(((t_cmd *)(content))->infile);
|
||||
if (fd1)
|
||||
close(fd1);
|
||||
if (fd2)
|
||||
close(fd2);
|
||||
}
|
||||
|
||||
int send_error_exec(char *input)
|
||||
@ -36,3 +40,9 @@ int send_error_exec(char *input)
|
||||
free(input);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
void ft_arrcpy(int *dst, int *src, int n)
|
||||
{
|
||||
while (n--)
|
||||
dst[n] = src[n];
|
||||
}
|
||||
|
Reference in New Issue
Block a user